Linux / UNIX: Clear bash history

Posted on in Categories , , last updated February 17, 2009

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

19 comment

  1. 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 !!!

  2. 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 ;)

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

  4. 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
    ——

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

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

Leave a Comment