Linux / UNIX: Clear bash history

by on October 15, 2007 · 19 comments· LAST UPDATED February 17, 2009

in , ,

Q. I'm using CentOS Linux server and how do I clear bash history in UNIX / Linux / BSD operating systems?

A. Type the following command to clear your bash history:

>~/.bash_history

Another option is link ~/.bash_history to /dev/null:
ln -sf /dev/null ~/.bash_history

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 19 comments… read them below or add one }

1 Rodrigo February 17, 2009 at 3:55 pm

Hi !

The sintax is wrong, it shoud say: ln -sf /dev/null ~/.bash_history or else you would be pointing /dev/null to bash_history

great site !!!

Reply

2 nixCraft February 17, 2009 at 4:50 pm

Thanks for the heads up!

Reply

3 jack March 12, 2009 at 10:06 pm

1) Another option is link ~/.bash_history to /dev/null:
ln -sf /dev/null ~/.bash_history

2) The sintax is wrong, it shoud say:
ln -sf /dev/null ~/.bash_history

both these look identical to me!
tell u what tho, it is syntax and NOT sintax ;)

Reply

4 Sorin Roiban May 27, 2009 at 6:06 pm

history -c

Reply

5 kittu October 24, 2010 at 11:46 am

u rock man…………….

Reply

6 Partha May 22, 2011 at 7:58 am

Its great yaar. command working cool.

Reply

7 Pinoy July 5, 2011 at 5:31 pm

history -c works! Thanks

Reply

8 mahbub September 22, 2012 at 4:10 pm

thank’s man

Reply

9 EZLinux August 14, 2012 at 5:00 pm

lol and it’s that easy… Nice one.

Reply

10 Franco Springveldt April 7, 2010 at 8:55 am

So simple!

Reply

11 Vkram August 4, 2011 at 5:30 am

ln -sf /dev/null ~/.bash_history
It is also good
but why take long, When there is already shortcut
history -c
Best Command

Reply

12 Ashok October 14, 2011 at 7:53 am

Simply use bellow command to clear history

>history -c

Reply

13 qweeak March 21, 2012 at 5:50 pm

The idea behind clearing history is that nobody know it is being cleared. This is the command that does it
——
history -d $((HISTCMD-1)) && history -c
——

Reply

14 anil krishn April 25, 2012 at 12:22 pm

great yaar its too much good & easier
>history -c

Reply

15 Prashanth July 12, 2012 at 8:10 am

Hello All,

I am using Putty Interface to connect to Linux server in windows machine. I want to de-activate UP Down arrow key or remove the history stored in these up down arrow key. Is it possible?

Note : I don’t want to remove the entire history stored in ~./bash_history

Regards,
Prashanth D

Reply

16 Raj January 12, 2013 at 7:57 pm

history -c command delete history on temporary basis not permanently after reboot deleted history comes back

Reply

17 shan March 15, 2013 at 2:53 pm

ok guys had a go too

history -c knocks all out but as Raj says it comes back after reboot
to make it stick you need to run history -w afterwards

so :

to remove all

history -c then history -w

to remove one line same principle

history -d 345 then history -w

Reply

18 sean March 27, 2013 at 12:11 pm

or use “history -cw”

Reply

19 ozangel December 6, 2013 at 6:50 pm

DO NOT enter
>~/.bash_history
It will re-run all the commands in the history, which is extremely dangerous!!

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: