Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
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?

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?