[colug-432] Search Command History

Jim Wildman jim at rossberry.com
Tue Feb 11 06:38:14 EST 2014


With bash
!?phrase
will search for and execute that last command containg phrase

history | grep apt (as others said) will find the command, with the
command number in front

!number will execute that command
!number:s/oldphrase/newphrase/  will edit and then execute the command

you can do similar things with the 'fc' command which will open your
default editor with the given command. The command executes when you
exit the editor.

   983  exit
   984  ls
   985  ls
   986  cd rossdev
   987  ls
   988  cat rbhosts.txt
   989  svn up
   990  exit
   991  scdr
   992  pine
   993  screen
   994  scdr
   995  scdr
   996  scdr
   997  exit
   998  scdr
   999  exit
  1000  scdr
  1001  man fc
  1002  history 20

fc 988
opens vi with "cat rbhosts.txt" in the buffer

When I see someone who only uses the arrow keys, I know they have not
gotten serious about efficient command line use.
> csh (sorry, no idea off the top of my head). 
> 
> Alternately, if you need a reason to use zsh, here's one more:  you can type
> 'apt' and then use the up arrow to reverse through full commands in your
> history that start with "apt".
> 
> 
> 
> 
>

----------------------------------------------------------------------
Jim Wildman, CISSP, RHCE       jim at rossberry.com http://www.rossberry.net
"Society in every state is a blessing, but Government, even in its best
state, is a necessary evil; in its worst state, an intolerable one."
Thomas Paine


More information about the colug-432 mailing list