Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Search a command in bash history

Date: 2010-04-12 00:00:00 -0400

When you type long commands like this one to display only certain fields of the squid log file.

tail -f  /var/log/squid/access.log | awk '{print $3,$4,$5,$7,$9}'

You do not want to type it again, every time you need it, so, you use history, you can find it by using.

history | grep tail

You will see an output like this

 967  tail -f  /var/log/squid/access.log | awk '{print $3,$4,$5,$7,$9}'

And then run it with:

!967

or you can run

!tail

And history will search for the command starting with tail, and will execute it.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.