Skip to main content
stinky.blog

bash history

History #

bash keeps all recently used commands in ~./bash_history

To see all recently used bash commands:

history

Ctrl + r To search history

To repeat a command by its line # on 'history':

!nn

Repeat last command that starts with letter a:

!a

Repeat last command with sudo:

sudo !!

History settings #

Set two environment variables $HISTSIZE and $HISTFILESIZE

echo 500 $HISTSIZE or $HISTFILESIZE

to make permanent, add to ~/.bashrc

export HISTFILESIZE=500
export HISTSIZE=500

Write current history to history file:

history -w

Clear current history:

history -c

Clear specific line:

history -d nn

History file is not merged until terminal exit