How to search Terminal command history
Written by Brent Sheets
Not 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.
With the Terminal window active, press Control+R and the 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
- Open .bash_profile in your text editor of choice
- Add this:
- Save and exit
If you do not have a .bash_profile
- Start Terminal
- Navigate to the Home folder by entering:
- Create .bash_profile by entering:
- 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
- Lastly, add this to the .bash_profile file:
- 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.