Display the history and optionally grep

Ever wondered how good it would be to have a command/function that would display the history or display the history with grep.

Would be really good right, well someone thought about this 🙂

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

Place this in your .bash_profile and you can use it two different ways. If you issue \’h\’ 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 \’cd\’

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

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/M_TyUNnb_IA/display-the-history-and-optionally-grep

\"Reblog

About Amit Agarwal