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
add comment

6 Answers

up vote 37 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
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
add comment

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
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
add comment

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
add comment

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
Actually, the other way around worked for me. –  kristianp Feb 1 at 0:43
add comment

execute the following commands to clear history forever

history -c && history -w

good luck!

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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