Clear Shell History In Ubuntu Linux

in Categories BASH Shell, Commands, Ubuntu Linux last updated August 1, 2013

How do I clear the shell history in Ubuntu Linux?

Command history allows you to find and reissue previously typed commands. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly. You may pass sensitive information such as passwords and it is stored in shell history file. Use the following tips to either delete your history or disable it.

Clear bash shell history command

To clear the history, type the following command:
history -c
rm ~/.bash_history
You can add the command to your ~/.bash_logout so that history will get cleared when you logout:
echo 'history -c' >> ~/.bash_logout

Prevent a bash history file from ever being saved

Add the following commands to ~/.bashrc file:
echo 'unset HISTFILE' >> ~/.bashrc
echo 'export LESSHISTFILE="-"' >> ~/.bashrc

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 10 comments/add one below):

10 comment

  1. any of you guys know how to make sure your history is NEVER wiped out?

    i use the amazing
    incremental history searching from here

    and would like to always have my history
    whereas on Ubuntu it gets wiped out every so often

    i guess it will be something like echo ‘whateveristhecommandhere’ >> ~/.bashrc

  2. I personally like to use this basic command to clear the history

    # history -c

    history [option] – c means clear the history

  3. I just tried this on ubuntu 14 and found that history -c did NOT remove the contents of my .bash_history file, so I have to run both commands:

    “`history -c
    rm ~/.bash_history“`

    1. File recovery programs on the ~/.bash_history which is obvious. Learn about file recovery on Linux (e.g. versus Windows or Mac), for an overview of basic computer forensics.

    Have a question? Post it on our forum!