Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching your command history on macOS terminal

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?

like image 324
Aipi Avatar asked Jan 21 '17 14:01

Aipi


People also ask

How do I find command history on Mac Terminal?

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.

How do I check command history in Terminal?

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.

Does Mac Terminal have history?

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.

How do I find command history?

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.


2 Answers

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  
like image 53
Inian Avatar answered Oct 05 '22 07:10

Inian


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.

like image 38
Sahil Chhabra Avatar answered Oct 05 '22 07:10

Sahil Chhabra