MacOS – How to edit bash shell terminal history

bashcommand linehistorymacosterminal

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?

Best Answer

Editing the .bash_history is just a matter of opening the file with an editor. There are a couple of ways you could achieve this.

  1. In the Terminal just type 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.
  2. Make the file visible by following these instructions, for instance, open it as any other file, modify it, and save.
  3. In the Terminal just type 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.