≡ Menu

Clear Shell History In Ubuntu Linux

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

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Estimated completion time1m
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
OR
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

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

{ 9 comments… add one }

  • Jonas September 7, 2011, 2:27 pm

    guess you mean
    echo ‘history -c’ >> ~/.bash_logout
    …to clear history on logout?

    Jonas

  • Brett Alton July 31, 2013, 4:24 pm

    Jonas is correct, FYI, in case you want to update this post…

    • nixCraft August 1, 2013, 6:03 am

      @Jonas/ Brett:

      Thanks for the heads up!

      • Brett Alton August 1, 2013, 5:13 pm

        Np, thanks for the wonderful website!

  • shan August 8, 2013, 6:55 am

    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

  • manzoor March 11, 2014, 12:00 pm

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

    # history -c

    history [option] – c means clear the history

  • Programster May 3, 2014, 8:34 am

    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“`

  • Rohit Mane June 3, 2014, 3:24 pm

    i know but how to delete history perminentely ????

  • javier January 24, 2015, 5:45 pm

    That was useful. Is there any chance to recover deleted history?

Leave a Comment