Apple - How can I delete saved commands from Terminal?
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
~/.bash_history
) - you can list and edit the history with the
history
command
With man bash
(in the SHELL BUILTIN COMMANDS
section) you will find the description of the different options.
You can:
list the history entries
$ history
delete the whole history
$ history -c
delete a given entry
$ history -d offset
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 .bash_history
This means the file is: /Users/{username}/.bash_history
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.
For Mac Terminal user
delete bash commands history with the following command
$ echo '' > ~/.bash_history
For Mac zsh user
delete zsh commands history with the following command
$ echo ''> ~/.zsh_hostory