How do I clear the terminal History?

I am using Linux Mint 17.1 Rebecca for about 2 days and accidentally typed my password into the terminal which is now displayed in the history list of commands I have previously typed.

I want to clear the terminal history completely. I have tried using the following commands in the terminal which I thought would clear the history forever but they do not:

history -c
reset
tput reset

The above commands “will” clear the history from the terminal but when I exit and bring up a new one all my previous history is still there and can all be listed again using the – history command and also by pressing the UP arrow on my keyboard. I do not want this to happen until I have totally cleared my history, then I want to continue using it.

How can I clear my terminal history completely – forever and start fresh?

Please Note: I do not want to exit the terminal without saving history just clear it forever in this one instance.

Asked By: Shambhala

||

reset or tput reset only does things to the terminal. The history is entirely managed by the shell, which remains unaffected.

history -c clears your history in the current shell. That’s enough (but overkill) if you’ve just typed your password and haven’t exited that shell or saved its history explicitly.

When you exit bash, the history is saved to the history file, which by default is .bash_history in your home directory. More precisely, the history created during the current session is appended to the file; entries that are already present are unaffected. To overwrite the history file with the current shell’s history, run history -w.

Instead of removing all your history entries, you can open .bash_history in an editor and remove the lines you don’t want to keep. You can also do that inside bash, less conveniently, by using history to display all the entries, then history -d to delete the entries you don’t want, and finally history -w to save.

Note that if you have multiple running bash instances that have read the password, each of them might save it again. Before definitively purging the password from the history file, make sure that it is purged from all running shell instances.

Note that even after you’ve edited the history file, it’s possible that your password is still present somewhere on the disk from an earlier version of the file. It can’t be retrieved through the filesystem anymore, but it might still be possible (but probably not easy) to find it by accessing the disk directly. If you use this password elsewhere and your disk gets stolen (or someone gets access to the disk), this could be a problem.

Instead of removing all your history entries, type these commands in your terminal:

  1. history -c (for delete history)
  2. history -w (save history)
Answered By: user171143

As a neophyte faced with the same problem I resorted to the rather the rather brutal expedient of deleting and recreating the history file:-

rm .bash_history
touch .bash_history

It worked for me without giving rise to any unpleasant side effects that I’m aware of.

Answered By: Hairy Joe

Type: history -c; rm ~/.bash_history

history -c clears your current session’s history, rm ~/.bash_history clears your long term history, so history -c; rm ~/.bash_history clears both.

Answered By: ANTHONY

I have tried history -c but the history comes back once we exit and reopens.This helped me.

cat /dev/null > ~/.bash_history && history -c && exit

This clears the history saved in the history file as well as the history in the current session (so that it’s not saved to file when bash exits). It then exits the shell. The next shell session will have no history.

Answered By: athul

Because there is a security issue here, you should consider securely deleting the history file.

$ shred -u ~/.bash_history && touch ~/.bash_history
Answered By: C0D3R3D

I use these two commands together and it perfectly clears everything:

>~/.bash_history;history -cw;
Answered By: Mojtaba Rezaeian
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.