November 17, 2014
Have you ever spent time at your computer trying to find an awesome terminal command that you typed in recently by using the up arrow to no avail? I know that I certainly have! Fortunately many kind and knowledgeable people have shared their tips and trick with me over time. In an effort to spread more knowledge about bash I’m going to share one of my favorite time and headache savers right now, with more to come in the future.
Probably the most recent shortcut that I’ve learned in the terminal is reverse searching. This is accomplished by pressing
ctrl + r, which brings up a search line below the last line in the terminal.
Once this is there you can type in a word that is in the command and it will find the most recent existence of it in your terminal command history. If the first match isn’t the command you’re looking for you can cycle through the other matches using
ctrl + r to go through each one.
As you search through your history if you want to abort the search you can use
ctrl + g. If you find the command that you are looking for pushing
enter will execute that command. On the other hand if you don’t want to execute it, but you still want to manipulate it in the terminal if you can push
esc, which will exit the search and put that command on the last line of the terminal.
I tend to use this one a lot when I know that I did a recent command to run a JSX or CoffeeScript compiler. As I don’t type out the commands all that often, but I know that the command is in my history and it is easy to obtain with a few keystrokes. Let me know if you have any favorite bash terminal command time savers!