How To Clear Bash History In Linux?

Published September 26, 2024

Problem: Managing Bash History

The Bash shell in Linux keeps a record of commands entered by users, which you can access using the history command. Sometimes, you may need to clear this history for privacy or security reasons.

Clearing Bash History: The Basic Method

Using the history Command

The history command in Linux helps you manage your Bash command history. You can view, edit, and clear your command history with it.

To clear your Bash history:

  1. Open your terminal.
  2. Type history -c and press Enter. This clears the current session's history.
  3. Type history -w and press Enter. This writes the empty history to the history file.

The history -c command removes all entries from the history list. The history -w command writes the current history to the history file, usually ~/.bash_history.

Note that these commands only clear the history for the current user. To clear the history for other users, you need to repeat this process while logged in as those users or have the right permissions to change their history files.

Tip: Verify Cleared History

After clearing your Bash history, you can verify if it was successful by typing history and pressing Enter. If the history was cleared correctly, you should see only the most recent commands, including the ones you used to clear the history.