Clear Shell History In Ubuntu Linux

by on July 7, 2009 · 8 comments· LAST UPDATED August 1, 2013

in , ,

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 8 comments… read them below or add one }

1 Jonas September 7, 2011 at 2:27 pm

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

Jonas

Reply

2 Brett Alton July 31, 2013 at 4:24 pm

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

Reply

3 nixCraft August 1, 2013 at 6:03 am

@Jonas/ Brett:

Thanks for the heads up!

Reply

4 Brett Alton August 1, 2013 at 5:13 pm

Np, thanks for the wonderful website!

Reply

5 shan August 8, 2013 at 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

Reply

6 manzoor March 11, 2014 at 12:00 pm

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

# history -c

history [option] – c means clear the history

Reply

7 Programster May 3, 2014 at 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“`

Reply

8 Rohit Mane June 3, 2014 at 3:24 pm

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

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: