How to Clear BASH Command Line History in Linux

The bash history keeps a record of all commands executed by a user on the Linux command line. This allows you to easily run previously executed commands by using the “up arrow” or “down arrow” keys to scroll through the command history file.

In this article, we will show you two simple ways to clear your command-line history on a Linux system.

The major reason for removing command-line history from the Linux terminal is to prevent another user, who could be using the same account.

For instance if you have typed a command that contained a password in plain-text and you don’t want another system user or an attacker to see this password, you need to delete or clear the history file.

Take a look at the command below, here the user aaronkilik has typed the database server password on the command line.

$ sudo mysql -u root [email protected]!#@%$lab

If you look into th bash history file towards the end, you will see the password typed above in there.

$ history
Check Last Executed Commands
Check Last Executed Commands

The bash_history file is normally located in a user’s home directory /home/username/.bash_history.

$ ls -l /home/aaronkilik/.bash_history

To remove a single line from the history file, use the -d option. For example, if you want to clear a command where you entered clear-text password as in the scenario above, find the line number in the history file and run this command.

$ history -d 2038

To delete or clear all the entries from bash history, use the history command below with the -c option.

$ history -c

Alternatively, you can use the command below to delete history of all last executed commands permanently in the file.

$ cat /dev/null > ~/.bash_history 

Note: A normal user can only view his/her own command history, but the root user can view the command history of all other users on the system.

You can learn more about the bash history file and useful history commands here: The Power of Linux “History Command” in Bash Shell.

Always remember that all commands you run are recorded in a history file, so do not type plain-text passwords on the command line. If you have questions or thoughts to share with us, make use of the feedback form below.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

6 thoughts on “How to Clear BASH Command Line History in Linux”

  1. I opened the .bash_history file. Found the line I wanted to delete. ‘

    $ history -d "#### "

    Went back to .bash_history. The line was still there…

    Went and edited in vim



Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.