
This has the same effect as pressing the Up arrow once to view the previous command and then pressing Enter. To re-run the last command you ran, type the following. That’s the command with a “12” to the left of it when you run the history command. To run a specific command from your history by its number, use the following command: !#įor example, let’s say you wanted to run the 12th command from your bash history. Just type them at the prompt and press Enter to run them like you’d run any other command. This feature is known as “history expansion” and uses an exclamation mark, known as a “bang”. history | tail -5īash can quickly “expand” previous commands, or expand them and modifying them. For example, the following command would show the last 5 entries in your history. You could also pipe it to the tail command to view only a small number of the recent commands you’ve run. For example, you could pipe it to the grepcommand to search your command history. You can do anything you like with the output. RELATED: Become a Linux Terminal Power User With These 8 Tricks The command with a “1” next to it is the oldest command in your bash history, while the command with the highest number is the most recent. You’ll see a list of all the commands in your bash history, along with a number to the left of each. You can print your entire bash history to the screen by running a single command: history


Press this shortcut and start typing to search your bash history for a command.


To scroll through your bash history, you can use a few of bash’s many useful keyboard shortcuts. RELATED: The Best Keyboard Shortcuts for Bash (aka the Linux and macOS Terminal)
