How to search Terminal command history

Search Terminal Command HistoryNot every Mac user is a Terminal jockey with instant recall of every available command. I often forget the syntax of a Terminal command that I may have used only a few days ago. Thankfully, the Terminal application is happy to remind us of our previous commands, if we only ask. Here’s how.

During a Terminal session, you may need to use the same command or a slightly edited version of the same command. For instance, changing YES to NO and that type of minor edit. If you’re in the same session, you can simply use the Up key to navigate to your previous commands.

But suppose you had meticulously typed in a long Terminal command several weeks ago and have now forgotten the arcane syntax. What to do? Cursing Terminal won’t help (believe me, I know). Try this instead.

terminal reverse-i-search

With the Terminal window active, press Control+R and the reverse-i-search prompt will appear. Now simply start typing the first few characters of a previously used command – and the entire command will display. This is invaluable for those of us with short memories and long commands.

increase the size of terminal history

If you like the idea of Terminal reminding you of previous commands, then you may wish to increase the size of your Terminal history file – for even more history storage.

Warning! Do not experiment with Terminal commands or instructions. If you don’t understand what a Terminal command does – then don’t use it. It is extremely easy to trash your system settings using Unix commands. Consider yourself warned.

If you have a .bash_profile

  1. Open .bash_profile in your text editor of choice
  2. Add this:
    HISTFILESIZE=1000000000 HISTSIZE=1000000
  3. Save and exit

If you do not have a .bash_profile

  1. Start Terminal
  2. Navigate to the Home folder by entering:
    cd ~/
  3. Create .bash_profile by entering:
    touch .bash_profile
  4. Now, either edit .bash_profile in your favorite text editor or type this in the Terminal window to automatically open the file in the default TextEdit:
    open -e .bash_profile
  5. Lastly, add this to the .bash_profile file:
    HISTFILESIZE=1000000000 HISTSIZE=1000000
  6. Save and exit

list terminal commands

And don’t forget, you can also make Terminal list over 1,400 commands whenever you wish to browse the possibilities.

Comments are closed.

E-mail It