≡ Menu

history feature

Bash / CSH shell offers command history feature. Most of you may be aware and using of UP / DOWN arrow keys to recall previous commands. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous ommand into the current input line, or fix errors in previous commands quickly.

To repeat last command that started with bar word type i.e. refer to the most recent command starting with string bar):
! bar

For example, let us run lighttpd to test config file:
# /usr/sbin/lighttpd -t -f /jail/usr/local/etc/lighttpd/lighttpd.conf

Syntax OK

Type few commands:
# pwd
# date

Now to repeat last command that started with lighttpd word type
# !lighttpd

lighttpd -t -f /jail/usr/local/etc/lighttpd/lighttpd.conf
Syntax OK 

Want to refer to the previous command, just enter

Related shell tip