≡ Menu

Clear Linux / UNIX BASH Shell Command Line Cache / History

Q. I just noticed faq about clearing dns cache and there are lots of commands stored in my cache. Can you tell me the command to clear out my command history or cache from a shell prompt?

A. Many programs read input from the user a line at a time. The GNU history library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in composing new ones. Bash and other shell may use this history library. The default fie is ~/.history or ~/.bash_history.

To display the history list with line numbers, enter

$ history

  4  cd /tmp/
    5  wget http://downloads.wordpress.org/plugin/cleaner-dashboard.1.1.zip
    6  unzip cleaner-dashboard.1.1.zip 
    7  su - 
    8  vi /etc/httpd/testing.lan.cyberciti.biz.conf
    9  service httpd restart
 997  vnstat -m -i eth1
  998  date
  999  yum update
 1000  w
 1001  ~/scripts/clean.cache rss squid web
 1002  history

Note: Lines listed with the a * have been modified.

To clear the history, enter:

$ history -c
The -c option causes the history list to be cleared by deleting all of the entries. For more information, enter:
$ help history

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 14 comments… add one }
  • Morgenster February 5, 2008, 6:44 am

    I have found this site very useful which comes with straight forward explanations, thanks a lot. morgen musonza

  • sontn June 5, 2009, 7:05 pm

    Hi, Thank you very much.

    I also found in your site very useful, I am newcomer to linux operating system.

  • Hardik March 23, 2010, 5:33 pm



  • Chad May 9, 2011, 11:35 pm

    Thanks this is just what I was looking for.

  • Amit August 24, 2011, 3:58 am

    There’s also the ~/.bash_history file that still needs to be deleted.

  • A.S.Qureshi September 9, 2011, 8:35 am

    Really. Good.

  • Anita singh October 10, 2011, 10:01 am

    Its good n helpful

  • Saevar Einarsson November 23, 2011, 6:30 pm

    Also you can make alias like
    alias clearhist=’rm ~/.bash_history;history -c;exit’
    This clear everything without leaving any sort of trail :)

  • sriram March 24, 2012, 7:27 am

    Thank u,

  • venkatesh July 11, 2012, 6:57 am

    nice command

  • Sara September 20, 2012, 6:25 pm

    I’m running konsole on a linux system. Evidently, when I did ‘Settings->Save as Default’ in the konsole shell, there were 30 lines of commands in the history at that time. Now, when I start a new shell and issue first command: history, those 30 lines are displayed. I have tried removing different files in the ~/.kde/share/config/ dir, and this will clear the saved schema but not the history. I have tried ’rm ~/.bash_history;history -c;exit’ as stated above and still no change.
    Does anyone know where that old history is stored and how on earth I can remove it?
    Many thanks

  • Rajandran R February 8, 2013, 4:33 am

    Thanks for the command reference. It worked great.

  • Faisal Ali May 21, 2013, 9:09 pm

    hi all,
    i realy very very happy of this web site
    because i need some thing related linux
    commands so i just type and get all details
    best regards
    and God Blease you

  • bala January 6, 2015, 6:18 am

    how to system arrive the free space percentage for FS

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , ,