22 Feb 2010
Linux shell commands
A number of commands and trick that I regularly use in Linux to make my life easier.
!$
Typing !$ into a bash command will substitute the last argument from the previous command.
[gavin@pc]: date > test.txt [gavin@pc]: cat !$ Mon Feb 22 12:02:53 WET 2010
!! will provide the whole of the previous command
[gavin@pc]: updatedb updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db' [gavin@pc]: sudo !!
Adding bind Space:magic-space to ~/.bashrc will mean that pressing space after entering either of these commands will immediately convert (e.g. !$ will be replaced with test.txt).
!* provides all of the arguments from the previous line, e.g.
[gavin@pc]: touch a.txt b.txt c.txt [gavin@pc]: chmod 777 !*
will create 3 files and set the permissions on each to 777.
Finally, using !somecommand will search backwards through the command history to match a command
[gavin@pc]: cat test.txt [gavin@pc]: date > test.txt [gavin@pc]: !ca Mon Feb 22 12:02:53 WET 2010
You don’t have to enter the whole command, just enough to match the line you want.