Display the history and optionally grep

2010-05-19 1 min read bash

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


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">

comments powered by Disqus