# How to clear bash history completely?

I want to clear all before command from history of my server. I use history -c it seems all things are cleared but when I ssh to the server,all commands are still there.

How can I clear them permanently?

-

~/.bash_history holds the history.

To clear the bash history completely on the server. You can open terminal and type cat /dev/null > ~/.bash_history

Other alternative way is to link ~/.bash_history to /dev/null

On my Ubuntu 12.10 box, The history comes back when I login back. I guess because the history entries has a copy in the memory and it will flush back to the file when you log out. The following command worked for me.

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

-
you can also put above command in .bashrc & .bash_logout . what it mean when you login u will have clear history & when you logout out your history will be cleared –  Qasim Sep 23 '12 at 6:06
Why do you need /dev/null there? Wouldn't > ~/.bash_hstory be enough? –  configurator Jan 10 '13 at 4:36
yes it would be enough! –  fromnaboo May 18 '13 at 15:40
It works good... –  Poovizhirajan.N Oct 5 '13 at 13:03
It seems that there exists several copies. One is for root and the others for other users. I can't find the other user's copies. –  Stallman Jun 24 '14 at 10:52

What to do:

In every open bash shell (you may have multiple terminals open):

history -w
history -c


Why: As noted above, history -c empties the file ~/.bash_history. It is important to note that bash shell does not immediately flush history to the bash_history file. So, it is important to (1) flush the history to the file, and (2) clear the history, in all terminals. That's what the commands above do.

-
Actually, the other way around worked for me. –  kristianp Feb 1 '14 at 0:43
In many cases, you can combine these two commands together: history -cw –  Elliot Apr 24 '14 at 22:52
For some reason this does not work on Ubuntu 14.04, probably others. It should but it doesn't. If you issue the command "history -cw" you can confirm with the up arrow that the history isn't there anymore, but if you start another terminal window (in Unity desktop) with shift + click on the terminal icon (I have it pinned in the launcher) the commands history are back, no matters how many times you do "history -cw". "cat /dev/null > ~/.bash_history" is the only way that worked for me. –  Hatoru Hansou Dec 4 '14 at 7:20
While I'm not Ubantu, works fine for my bash shell in OSX. –  Scott Biggs Jan 2 at 19:54

There's another much simpler one: running history -c on the terminal prompt and gone are all entries in the bash_history file.

-
No, it is not. Log out, log in, arrow-up gives me everything. You need the "history -w" too. –  stolsvik Nov 17 '13 at 19:31

Another way to do this is deleting the ~/.bash_history file by using rm ~/.bash_history command. When you login another time, the .bash_history file will be automatically created.

-
At least on some OSes ~/.bash_history is written to disk when you log out - Not sure about *buntus. –  d-_-b Jun 12 '13 at 23:41

execute the following commands to clear history forever

history -c && history -w


good luck!

-
rm ~/.bash_history; history -c; logout


Now log back in and witness that your arrow-up doesn't give you anything.

-
@KasiyA It's about a server and a ssh session, so no need to edit... –  Radu Rădeanu Oct 20 '14 at 20:29

Clear the current shell's history:

history -c


When you log out, your current shell's history is appended to ~/.bash_history, which is a cache of previous shells' histories, to a maximum number (see HISTFILESIZE in "man bash").

If you want to remove the history altogether, then you essentially have to empty out ~/.bash_history which many of the above entries have suggested. Such as:

history -c && history -w


This clears the current shell's history and then forces the current shell's history (empty) to overwrite ~/.bash_history....or to be more accurate, it forces it to overwrite HISTFILE (which defaults to ~/.bash_history).

Hope this helps.

-
You answer is accurate, but the question was two years old, had accepted answers, and included the same answer you have given. –  Charles Green Jul 10 '14 at 17:47

Try this one

edit your .profile and add the line below at the end of the file

rm -f .bash_history


this way, every time you login, it will delete your .bash_history file automatically for you. Adding the -r recursive remove option seems dangerous and not needed.

-

## protected by Community♦Aug 30 '14 at 22:52

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.