arzumy md short notes on small discoveries

How To Quickly Search Your Terminal History

Early 2011

One of a benefit of pair programming is you got to learn things that you don’t even know you need to learn. When I paired with Mike Mazur, one of the Pivotal Labs1 engineer, I got to learn a very useful trick.

When I want to refer to commands that I’ve used before, I’d do this:

  history | grep previous_command

Then I’d cut and paste the result to execute. Not ideal, but it worked for me. Because I didn’t know better.

Until he showed me the right way of doing it. Comes reverse-i-search. All you need to do is press ctrl + r in terminal and start typing the command you want to search for. For example, I want to search for server:

  ctrl + r
  serv
  => (reverse-i-search)`serv': jekyll --server --auto

If that’s not the command you looking for, just keep tapping ctrl + r until you find the right one. Then just press enter to execute. Handy!

Also, it would be better if you increase your history size. Just add these lines to your profile file, one of those .bashrc, .bash_profile or .profile.

  HISTFILESIZE=1000000000
  HISTSIZE=1000000

The size is up to you, I got those values from lifehacker.

  1. Now called Neo 

arzumy md, CTO at Fave and BillPlz.

https://www.facebook.com/arzumy
https://my.linkedin.com/in/arzumy
https://www.google.com/search?q=arzumy