What is the shortcut to search my command history in macOS terminal?
For how long is the history available for searching? Where is it stored?
Pressing ctrl + R will open the history-search-backward. Now start typing your command, this will give the first match. By pressing ctrl + R again (and again) you can cycle through the history.
In Linux, there is a very useful command to show you all of the last commands that have been recently used. The command is simply called history, but can also be accessed by looking at your . bash_history in your home folder. By default, the history command will show you the last five hundred commands you have entered.
With the Terminal in macOS, you can save lots of time and type less by using the command history functions built into the Terminal shell. The shell keeps a record of the commands you run, and you can access this history with a few simple keystrokes to run commands again or edit them so you don't have to retype them.
Open CMD from the Start Menu and type “doskey /History”. As you typed, all the commands which you typed latterly are shown to you in your CMD window. Use Up and Down arrow to select the command. Or you can also Copy and Paste the commands from the history that has appeared on your screen, within the CMD window.
How about using Ctrl+
R for searching on the Terminal
Utility in Mac
for searching on the command history,
dudeOnMac: freddy$ whoami freddy (reverse-i-search)`who': whoami
Well for controlling how long the history
would be retained that depends on a few shell
environment variables, HISTFILESIZE
which is nothing but number of lines of history you want to retain. Set a huge value for it in .bash_profile
for it to take effect
HISTFILESIZE=10000000
Use Ctrl
+ R
for searching a command from history in Terminal.
(reverse-i-search)`':
Type any substring of the command you want to search e.g. grep
(reverse-i-search)`grep': grep "XYZ" abc.txt
It will return the latest command that matches your input. If that is not the command you were searching for, keep pressing Ctrl
+ R
for next match until you find your command.
Once you found your command press Return
to execute it.
If you want to exit without running any command, press Ctrl
+ G
PS: This answer is same as suggested by Inian, just giving more details for easy usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With