Sometimes you have to execute a complex command that you’ve used in the past. Instead of using the up-arrow key to scroll through your previous commands one at a time, here are two ways you can run a command without typing it again.
1. The history command
- Type
historyand hitenter - Find the number of the command you want to run again
- Use one of the following commands:
!213runs command number 213!!runs the last commandsudo !!reruns the last command command as sudo
2. Reverse Search
- Use
control + rand the type one or two words from the command you’re looking for - Keep hitting
control + rto go back through the history and find the exact command you’re looking for - Once you’ve found what you’re looking for, hit
tabto autocomplete the entire command - Hit
enterto run the command
