Home / Clear the bash history

Clear the bash history

When entering commands in a bash shell each command is stored in the history which is written to the .bash_history file when logging out. This post shows how to clear the history for the current session, and how to clear all commands completely from the history.

Clearing the history for the current session

The first command below will clear the history for the current session only, resetting it back to how it was when you first logged in.

history -r

Any additional commands entered after running this will be added to the history.

Clearing everything from the history

To completely empty the history enter this command:

history -c

As with "history -r", any additional commands entered after this will be added to the history.

Note that the .bash_history file is only written to when you log out. So although the entire history in memory has been cleared, it still remains in the file until logging out. To ensure your history file is emptied immediately, run "history -c" and then log out from all active shells to the server.