Searching through bash history
Searching through history
When you need to find a previous command from your bash history you should:
- Type Ctrl+R to initiate a reverse search
- Start typing any part of the command
- 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:
- Type history and hit enter to list all items in your bash history
- Each item will be listed with a number in front
- 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`