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 ”$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: <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">
Related Articles:
- 2009/12/18 Display a block of text with delineated by a start pattern and an end pattern
- 2009/12/07 View the newest xkcd comic.
- 2010/05/19 bash script to change icon theme to check out all the installed themes (personal)
- 2010/05/12 Get the most favourite commands from commandlinefu
- 2010/05/11 Pipe stdout and stderr, etc., to separate commands