Skip to main content

The history command performs one of several operations related to recently-executed commands recorded in a history list.

# To display the commands history list with line numbers:
history

# To clear the commands history list (only for current 'bash' shell):
history -c

# To overwrite history file with history of current 'bash' shell (often combined with 'history -c' to purge history):
history -w

# To delete the history entry at the specified offset:
history -d <offset>

# ---

# To see most used top 10 commands:
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10

# To clear all previous history
history -c

# To disable history
export HISTSIZE=0

# To ignore specific commands from history
export HISTIGNORE="pwd:ls:ls -ltr:"

# To erase duplicates in history
export HISTCONTROL=erasedups

# Eliminate repeated entries from history
export HISTCONTROL=ignoredups