I entered a password in a command line pro or in a terminal window by mistake and do not want to remove my whole history. My shell is bash.
How do I edit my bash history in Mac OS X?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
.bash_history is just a matter of opening the file with an editor. There are a couple of ways you could achieve this.
vi ~/.bash_history, then edit the file as you want, and save. This option could be tricky, if you're not used to vi, of course.
open -e ~/.bash_history. This command will open the file with TextEdit, you can choose any other text editor, of course. Modify the file and save.
For the changes to be noticeable just restart the bash.
I think that Dmitry's answer is ideal if done before saving the history - by default, saving occurs on shell/terminal exit.
If you may have already saved the history to ~/.bash_history, then I prefer Thecafremo's answer, but I would suggest adding a step of exiting Terminal to ensure that none of the bash instances have loaded the history and will re-save it. This is especially tricky if you have multiple terminals and have enabled any sort of command-by-command history update.
Regardless of which method you use, I would add one step: verify success!
grep BAD_TEXT .bash_history! This new command would go into history. I'd just open .bash_history in your favorite editor and search within that for BAD_TEXT.
This should give you peace of mind that you have eliminated BAD_TEXT no matter what kind of crazy bash setup you may encounter.
There are several histories for example bash and zsh. You can do this with nano. To do this, simply open the terminal
With this you edit the bash history
With this you edit the standard zsh history
If you want, you can do the whole thing using TextEdit.
open -t $HOME/.bash_history
open -t $HOME/.zsh_history