One of the easiest ways to improve your productivity on unix systems is to become acquainted with your shell's history completion and search facilities. All of these described here are common to zsh and bash, although zsh has some additional features that bash does not.
Firstly, if you ever find yourself tapping the up arrow to scroll
through your command history, you are living in a state of sin- either
type history 100
or something similar to actually get a history list or
use Ctrl-R to do a recursive incremental search through your shell
history. Secondly, learn and use some basic history completions:
!$
completes to the last argument of your previous command. vi file
followed by git commit !$
edits a file and checks it in.!*
completes to all the arguments of your previous command. vi file1 file2 file{3,4,5}
followed by git commit !*
edits a list of files and checks then all in.!!
completes to the whole of your previous command, with args. vi /etc/passwd
gives "permission denied? Use sudo !!
to become rootly without retyping.There are lots more possible history completions but I use those three ten times for any one of them. Also useful are:
!something
completes to the whole of the last command I typed that began with "something
". So, for example, say I try vi file
and get "permission denied", but I don't yet have "sudo" permission sorted out. I become root, fix my sudoers file, then do sudo !vi
to run the whole of the last vi command as root.!somenumber
completes to the whole of a specific numbered command from my history.You can combine these with the first three constructs by adding a colon, so:
!vi:*
is "all the arguments to the last vi command. Perhaps I have edited
some files, then done a make to see if they build, then I can git commit !vi:*
to check the changes into git.!3:$
is the last argument to command number three from my history.permalink Updated: 2006-05-17