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 58 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
10  
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

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

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

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
    
In many cases, you can combine these two commands together: history -cw –  Elliot Apr 24 at 22:52

execute the following commands to clear history forever

history -c && history -w

good luck!

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

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

history -c && history -w; exit EDIT: (this works in Debian wheezy terminal. I feel it may be of use for Debian derivatives.)

EDIT#2: In the end I tried to copy instruction into a system file to force clear it upon logout. I gad 640 items at first. Then nearly 100.. I do not need that much history. Also I look at it in the aspect of I don't want a record of EVERY SINGLE THING, that seems like a security hole. Just a bit...

share|improve this answer
    
Say something more about why this works. –  enedil Jul 26 at 19:27
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  edwin Jul 26 at 23:16
    
Thanks. As you may have guessed that was my very first post. I apologize if I stepped on toes or took anything away. I was just noting in my newness that particular command had worked for me. I am quite new to Linux as it is. –  Tim Danielson Jul 27 at 1:38

Your Answer

 
discard

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.