Linux / UNIX: Clear bash history

last updated in Categories , ,

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


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

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

    Prashanth D

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

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

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

    Still, have a question? Get help on our forum!