Saturday, February 20, 2010

My favourite bash shortcuts

As a system administrator, the bash may be the linux tool you use most. So it may be a good idea to know a bit about the shortcuts that may speed up your job.
Here are my favourite ones :
Ctrl-a , to go to the beginning of the line
Ctrl-e , to go to the end of the line
Alt-b , to move backward one word
Ctrl-u , to delete everything to the left of the cursor
Ctrl-w , to delete the previous word

cd - , to go back to the previous directory

Ctrl-r , to search a previous command in the bash history. This, is a MUST shortcut. The one I prefer. Just type Ctrl-r and then, a few letters of a command that is in the history to find it and be able to execute it (the bash will do a pattern matching on the commands in your history). To look further in the history, you can type many times Ctrl-r.
Alt-. , to print the last argument of the last command. You can type many times this shortcut to look for an argument further in your history.

^foo^bar, to substitute the "foo" pattern in your previous command by the "bar" pattern and execute it.