Even before the
interactive command line editor of
tcsh (and other unofficial versions of csh and
zsh and
bash and others) existed,
csh had command line editing based on a
line editor paradigm. This facility still exists today in almost all of the "modern"
shells, and is worth learning. It's often a lot faster to type in a correction or modification to a command than to edit it appropriately!
Here I'll try to summarise some of the idioms I commonly use.
- !!
- As N-wing already noded, this just expands to the last command.
- !abc
- Expands to the last command starting with "abc".
- !123
- Expands to command #123 in the history list.
- !abc:4
- Expands to word 4 of the last command starting with "abc". Words are counted from 0, so !abc:0 is that line's command, and !abc:3 is its third parameter.
- !!:$ or !$
- Expands to the last word of the last command. Often used in idioms like this:
% some_tricky_command prm1 prm2 ... > /long/path/to/output
% grep 'regexp' !$
% more !$
- !abc:s/pattern/replacement
- Expands to the last command starting with "abc", with the first occurrence of pattern replaced by replacement. pattern is unfortunately not a regexp.
- ^wrong^right
- Short for !:s/wrong/right.
- !abc:gs/pattern/replacement
- Expands to the last command starting with "abc", with all occurrences of pattern replaced by replacement.
Teach your fingers to type these in automatically. It's a great way to semi-automate many tedious command-line tasks.