Mac terminal history - see , save, clear & search

 

* This guide is based on zsh  terminal on  Big Sur MacOS. 

Find all the commands from your terminal session

$ history 

-- shows short or partial list of your terminal commands history

like below...

 71  ls
   72  open .zsh_history
   73  open ~/ .zsh_history
   74  ~/.zsh_history
   75  sudo ~/.zsh_history
   76  touch ~/.zshrc
   77  touch ~/.zshrc_history
   78  touch .bash_history
   79  history 100
   80  history 10
   81  history
   82  history > terminal_history.txt
   83  touch terminal_history.text
   84  touch terminal_history.txt
   85  ls
   86  cat terminal_history.txt

$ history  0

-- this will show the maximum list of commands starting from 0 position

$ history 10 

-- this will show commands starting from 10 in list of all commands

 

Save Terminal commands history to a file,

$ history  0 > terminal_commands.txt

-- this   will save all available commands into 'terminal_commands.txt' in the current folder.

Clear Terminal History:

$ history -c

-- this will clear all commands from your terminal history 

To search the terminal history in mac:

$ ctrl + R  

Then type the part of the command to search. 

Comments