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?

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
19 comments… add one
  • Rodrigo Feb 17, 2009 @ 15:55

    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 Feb 17, 2009 @ 16:50

    Thanks for the heads up!

  • jack Mar 12, 2009 @ 22:06

    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 @ 18:06

    history -c

    • kittu Oct 24, 2010 @ 11:46

      u rock man…………….

      • Partha May 22, 2011 @ 7:58

        Its great yaar. command working cool.

    • Pinoy Jul 5, 2011 @ 17:31

      history -c works! Thanks

      • mahbub Sep 22, 2012 @ 16:10

        thank’s man

    • EZLinux Aug 14, 2012 @ 17:00

      lol and it’s that easy… Nice one.

  • Franco Springveldt Apr 7, 2010 @ 8:55

    So simple!

  • Vkram Aug 4, 2011 @ 5:30

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

  • Ashok Oct 14, 2011 @ 7:53

    Simply use bellow command to clear history

    >history -c

  • qweeak Mar 21, 2012 @ 17:50

    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 Apr 25, 2012 @ 12:22

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

  • Prashanth Jul 12, 2012 @ 8:10

    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

  • Raj Jan 12, 2013 @ 19:57

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

  • shan Mar 15, 2013 @ 14:53

    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 Mar 27, 2013 @ 12:11

    or use “history -cw”

  • ozangel Dec 6, 2013 @ 18:50

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.