4

How do I clear my Bash history in Mac OS X?

I've entered a few "errors" and just want to clear them off. How do I do that?

grg
  • 201,078
marz679
  • 41

3 Answers3

7

To clear it, just delete the ~/.bash_history file. If you want to just remove the offending lines you can open ~/.bash_history in the editor of your choice. For me, this would be

emacs ~/.bash_history

and then going to the beginning of each bad line and pressing control ^+K.

Or your can just fill your .bash_history with empty. Run this: (including the >)

 > ~/.bash_history
nohillside
  • 100,768
0942v8653
  • 7,412
3

You can run:

history -c

I use it often, so I made an alias to hc.

Thi G.
  • 2,284
  • Just to note, this works for clearing history from the current shell while my answer is for sessions that have already been closed. – 0942v8653 May 28 '14 at 01:26
2

To view your bash history enter the command:

history

You will get an index of your history.

You can clear your entire history like so:

history -c

You can clear the 45th item in your history like so:

history -d 45

(get you can see the history item numbers by executing the history command)

AllInOne
  • 1,645