As all of you know, Mac OS X stores all commands that run from Terminal in Terminal itself, however, I want to delete (for example) the last 3 commands from the terminal. How can I do this?
Mac OS does not store anything anywhere.
bash, which is the shell that is run in the terminal, does store the command history.
The terminal command history is stored in a hidden file in your user directory called
This means the file is:
You have to enable "Show System Files" to see it (from the "View" menu in finder).
The file is just a textual list of everything you type in the shell. You can open it in TextEdit, or your editor of choice.
You should probably close
Terminal.app to flush any recent changes into the file before making changes, or it may get overwritten from a version
Terminal.app has in memory.
It's not a Mac OS feature but a shell feature. Assuming that you are using bash (the default):
- the command history is stored in memory and persisted in a file (usually
- you can list and edit the history with the
man bash (in the
SHELL BUILTIN COMMANDS section) you will find the description of the different options.
list the history entries
delete the whole history
$ history -c
delete a given entry
$ history -d offset
In addition to Text Edit, Also, if you are old school, use 'vi' to edit the file and remove the offensive commands. Similar command-line editors are
emacs (which shares editing shortcuts with OS X) or
nano (which has simplified navigation and visual help on how to save and quit the editor without needing a reference sheet).