Display the history and optionally grep

2010-05-19 153 words 1 min read

Ever wondered how good it would be to have a command/function that would display the history or display the history with <a class="zem_slink" title="Grep" rel="wikipedia" href="http://en.wikipedia.org/wiki/Grep">grep.

Would be really good right, well someone thought about this πŸ™‚

$ h() { if [ -z &#8221;$1&#8221; ]; then history; else history | grep &#8221;$@&#8221;; fi; }

Place this in your .bash_profile and you can use it two different ways. If you issue &#8217;h&#8217; on its own, then it acts like the history command. If you issue:

h cd

Then it will display all the history with the word &#8217;cd&#8217;

* View this command to comment, vote or add to favourites * View all commands by haivu

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: <a href="http://feedproxy.google.com/%7Er/Command-line-fu/%7E3/M_TyUNnb_IA/display-the-history-and-optionally-grep">http://feedproxy.google.com/~r/Command-line-fu/~3/M_TyUNnb_IA/display-the-history-and-optionally-grep<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/90d298c1-644e-413c-a905-1b5b7a7d1e20/"><img class="zemanta-pixie-img" style="border: medium none ; float: right;" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_e11.png" alt="Reblog this post [with Zemanta]" width="79" height="20" /><span class="zem-script more-related pretty-attribution">


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it