Clear Bash History in Linux

Clear Bash History in Linux

In Linux operating system all executed commands are tracked and stored in the history file. It can be used to view and recall the past commands. However, for security reasons may be required to clear commands history. This tutorial shows how to clear Bash history in Linux.

By default, Bash history is stored in the ~/.bash_history file. Executed commands are not immediately written to this file. History entries are stored in the memory and appended to the file when log out.

The history command can be used for managing Bash history. The -c option allows to clear current history that is stored in the memory. However, this option will not affect the previous history that is stored in the history file. To write out the current history to the history file, use -w option. To completely clear Bash history, execute the following command:

history -c && history -w

The -c option clears current history and -w option writes out empty current history to the file.

In order to test, log out of the system and log in again. Run the following command to see history:

cat ~/.bash_history

Leave a Comment

Cancel reply

Your email address will not be published.