How to Clear Command Line 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 command line history list entirely, be it for privacy or security purposes.
This article will show you how to clear command line history in a terminal. This trick works to clear command history on a Mac OS or Linux machine, or even Windows with Ubuntu shell.
How to Clear Command Line History Completely
To clear out command history, you just need to attach a -c flag to the familiar history command, looking like so:
That command when executed will manually wipe the .bash_history file, or if you’re using a different shell it should wipe that too (zsh, tcsh, bash, etc).
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 of clearing command history, the video shows the procedure on Mac OS with the Terminal app, but everything would be the same in other operating systems that support clearing of command line history as well.
This should work the same at any bash shell, zsh shell, tcsh, and most other shells, regardless of whether the command line is in Mac OS X or linux, or even Windows linux shell (but not a DOS prompt).
Thanks to Ado for the tip idea. If you have any other helpful tips or tricks regarding clearing command history from a Terminal, share them in the comments!