Terminal

Bash scripts, command line tips, etc.

Searching through bash history

Searching through history

When you need to find a previous command from your bash history you should:

  1. Type Ctrl+R to initiate a reverse search
  2. Start typing any part of the command
  3. Once you found it use any of the arrow keys to start editing the command or hit enter to run the command immediately

Listing your entire history

In addition, you can also list every command using the history command:

  1. Type history and hit enter to list all items in your bash history
  2. Each item will be listed with a number in front
  3. You can then rerun any of the commands using the numeric value !10 or the negative (from bottom) value !-2

So an example:

$ history
1 clear
2 ls -al
3 nano ~/somefile.txt
4 history
$ !1
# This will run `clear`
$ !-2
# This will run `nano ~/somefile.txt`