
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
Output:
Syntax OK
Type few commands:
# pwd
# date
Now to repeat last command that started with lighttpd word type
# !lighttpd
Output:
lighttpd -t -f /jail/usr/local/etc/lighttpd/lighttpd.conf Syntax OK
Want to refer to the previous command, just enter
!!
Related shell tip
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











{ 2 comments… read them below or add one }
I also like to use Control-R to do a search of my history file to find commands that may not have been the last one that I ran.
Control-R will bring up a search dialogue where I can type in one part of my command…say, a package name or other, and it will find it and select it again. This speeds up remembering that one command you did last week :D
devnet,
Ah, I forgot about magical CTRL+R.
Appreciate your post!