Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Search through the history of commands in terminal

Admit it. Remembering a lot of terminal commands can be overwhelming and often tiring. What if I tell you there’s a pretty handy way of searching through all of your previous commands using a few keystrokes? Follow along.

Terminals in Linux and macOS have this nifty search called “reverse search” or reverse-i-search which you can invoke by typing a few keywords from your desired command and then pressing Ctrl + R.

So, for instance, if I want to find all the Artisan commands I’ve previously used, I could type “arti” and then press Ctrl + R and that will show me the recent command that contains “arti” like so.

Now, you can cycle through all the available commands by Ctrl + R until you get your desired command.

The vice-versa is also possible where you can press Ctrl + R and then type in your search keyword, which will work just like I’ve mentioned previously.

Behind the scene, the command will search through ~/.bash_history where the history of all the commands gets maintained.

Very handy, right?

👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I do and want me to continue doing the same, I'd like you consider leaving a tip. I'd highly appreciate that. Cheers!