I'm working in Mac OSX, so I guess I'm using bash…?
Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
bashcommand historycommand lineshell
I'm working in Mac OSX, so I guess I'm using bash…?
Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
Best Answer
Preventative measures
If you want to run a command without saving it in history, prepend it with an extra space
For this to work you need either
ignorespace
orignoreboth
inHISTCONTROL
. For example, runTo make this setting persistent, put it in your
.bashrc
.Post-mortem clean-up
If you've already run the command, and want to remove it from history, first use
to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run
Additionally, if the line you want to delete has already been written to your $HISTFILE (which typically happens when you end a session by default), you will need to write back to $HISTFILE, or the line will reappear when you open a new session: