Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

8 Answers 8

up vote 61 down vote accepted

~/.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

share|improve this answer
13  
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
13  
Why do you need /dev/null there? Wouldn't > ~/.bash_hstory be enough? –  configurator Jan 10 '13 at 4:36
2  
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 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.

Reference: http://www.giannistsakiris.com/index.php/2007/09/13/how-to-clear-bash-history-and-what-to-watch-out-for/

share|improve this answer
1  
Actually, the other way around worked for me. –  kristianp Feb 1 at 0:43
2  
In many cases, you can combine these two commands together: history -cw –  Elliot Apr 24 at 22:52

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

share|improve this answer
    
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.

share|improve this answer
2  
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!

share|improve this answer

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.

share|improve this answer
1  
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 at 17:47
rm ~/.bash_history; history -c; logout

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

share|improve this answer
    
Do you want to solve this problem by DELETING the .bash_history file?? –  KasiyA Aug 30 at 19:46

Try this one

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

rm -rf .bash_history

this way, every time you login, it will delete your .bash_history file automatically for you.

share|improve this answer
2  
"clear bash history" not DELETE the ".bash_history" file!! –  KasiyA Aug 30 at 18:19

protected by Community Aug 30 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.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.