history (Command History)
The history command displays a list of the commands you have executed since you started the current session. It is an essential tool for re-running previous commands and increasing terminal productivity.
1. Basic Usage
history
2. Essential Shortcuts (The Power User Way)
| Shortcut | Description |
|---|---|
| Ctrl + r | Reverse Search. Type a keyword to search through your history interactively. |
| !string | Runs the most recent command that starts with "string". |
| !$ | Refers to the last argument of the previous command. |
| history -w | Force-writes the current session history to the history file. |
3. Practical Examples
① Finding a long command you forgot
history | grep "tar"
② Executing the last command again
!!
③ Deleting a specific history entry
history -d 1024
4. [Tip] Customizing History Size
You can change how many commands your system remembers by editing the HISTSIZE and HISTFILESIZE variables in your .bashrc file. Setting them to a larger number is common for power users who want to keep years of command history.