How to Clear Command Line History

Dec 17, 2012 - 7 Comments

Clear command line command history

If you’re a frequent command line user, you’re likely to have found the history command to be quite useful before, whether it’s for discovering your most frequently used commands, dumping history and searching it to find specific past commands, listing all defaults commands used, or whatever else. That said, there are some obvious situations where you may want to remove that history list entirely, be it for privacy or security purposes.

To clear out history, you just need to attach a -c flag to that same history command:

history -c

That will manually wipe the .bash_history file. Obviously that file could be targeted directly with rm as well, but it’s best to stick with the history command for a variety of reasons.

If you wish to verify the command worked, type ‘history’ again as usual, and you’ll discover the only command listed is “history -c”. The brief video below demonstrates this entire process.

This should work the same at any bash shell, regardless of it being in Mac OS X or linux.

Thanks to Ado for the tip idea

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Mac OS X, Tips & Tricks


» Comments RSS Feed

  1. pkt says:

    Should work with other shells as well, but .sh_history, .tsch_history etc are easy to remove anyway.

  2. bv7 says:

    Thanks I didn’t know this command It’s good :)

  3. Peter says:

    Keeping the history file can be useful:

    Bash has an instant reverse search function. To search through old commands, press cmd-R and then start typing any part of a command previously used. Quite handy…

  4. @Peter says:

    I think you mean ctrl-R.

  5. steve says:

    if you want exit without saving the history session:

    $ kill -9 $$

  6. nolan says:

    how about if you dont want history saved at all and tired of typing history -c. HISTSIZE=0 will not save anything to history.

  7. roxb says:

    bash clean history

    alias cleanH=’history -c;echo “”> ~/.bash_history’

    add alias in ~/.bashrc


Leave a Reply


Shop for Apple & Mac Deals on

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad