Command History
Bash remembers your previous commands.
View history
history # All history
history 20 # Last 20 commands
History shortcuts
| Shortcut | Action |
|---|---|
↑ / ↓ | Previous / next command |
Ctrl+R | Reverse search — type to search history |
!! | Repeat last command |
!n | Run command number n |
!text | Run last command starting with text |
!$ | Last argument of previous command |
Ctrl+P | Previous command (same as ↑) |
Search history
history | grep ssh
history | grep apt
Clear history
history -c # Clear current session history
history -d 100 # Delete entry 100
rm ~/.bash_history # Delete history file
History file
cat ~/.bash_history
Useful settings in .bashrc
export HISTSIZE=10000 # In-memory history
export HISTFILESIZE=20000 # On-disk history
export HISTCONTROL=ignoredups # No duplicate entries
export HISTTIMEFORMAT="%F %T " # Add timestamps