≡ Menu

Linux / UNIX: Clear bash history

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:


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

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 19 comments… add one }

  • Rodrigo February 17, 2009, 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 !!!

  • nixCraft February 17, 2009, 4:50 pm

    Thanks for the heads up!

  • jack March 12, 2009, 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 ;)

  • Sorin Roiban May 27, 2009, 6:06 pm

    history -c

    • kittu October 24, 2010, 11:46 am

      u rock man…………….

      • Partha May 22, 2011, 7:58 am

        Its great yaar. command working cool.

    • Pinoy July 5, 2011, 5:31 pm

      history -c works! Thanks

      • mahbub September 22, 2012, 4:10 pm

        thank’s man

    • EZLinux August 14, 2012, 5:00 pm

      lol and it’s that easy… Nice one.

  • Franco Springveldt April 7, 2010, 8:55 am

    So simple!

  • Vkram August 4, 2011, 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

  • Ashok October 14, 2011, 7:53 am

    Simply use bellow command to clear history

    >history -c

  • qweeak March 21, 2012, 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

  • anil krishn April 25, 2012, 12:22 pm

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

  • Prashanth July 12, 2012, 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

    Prashanth D

  • Raj January 12, 2013, 7:57 pm

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

  • shan March 15, 2013, 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

  • sean March 27, 2013, 12:11 pm

    or use “history -cw”

  • ozangel December 6, 2013, 6:50 pm

    DO NOT enter
    It will re-run all the commands in the history, which is extremely dangerous!!

Leave a Comment