Clear Bash History

history -c

Linux Bash History File


Check out more about bash history file.

Scrolling through Bash History

  1. UP arrow key: Scroll backwards in history
  2. CTRL-p: Scroll backwards in history
  3. DOWN arrow key: Scroll forwards in history
  4. CTRL-n: Scroll forwards in history
  5. ALT-Shift-.: Jump to the end of the history (most recent)
  6. ALT-Shift-,: Jump to the beginning of the history (most distant)

Linux Bash Search History

Checkout different ways to search Bash search history.

  1. History and Pipe to grep
history | egrep <cmd>
  1. CTRL-r to do bash reverse history search

press ctrl-r and type the partial or complete word of the command you are trying to search.

Example: In the above snapshot, I did following...

  1. ls ~/.bash_history
  2. Ctrl+r
  3. ba
  4. Hit Enter

In step 3 above, after I press Ctrl+r, I typed "ba" and the whole command "ls ~/.bash_history" showed up.

Execute Previous Command Using ! (bang)

Use double bang as shown below...


If you want to execute previous command from history based on command number do following...

  1. history | less
  2. Note down the command number that you want to run
  3. !n

Example, let say you want to run command number 80, run following command...


If you want to run a command which was n number of commands before the current command, do following...

Example: Run 4th previous command.