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 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:
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