Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 12 down vote accepted

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 to flush any recent changes into the file before making changes, or it may get overwritten from a version has in memory.

share|improve this answer
Commands are not stored on the fly but only when the shell exits or when prompted to do so (e.g., history -a or history -w). Usually the last commands are not yet in the file. – Matteo Dec 21 '11 at 6:20
thank you so much ... – JAHelia Dec 21 '11 at 7:09
Whoops, I meant to add you should probably close all instances of before editing this file. Fixed. – Fake Name Dec 21 '11 at 8:18

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
share|improve this answer
both answers are correct, i chose the earliest one .. thank you bro .. – JAHelia Dec 21 '11 at 7:15
on doing history -c, it says fc: event not found: -c. Then I manually opened the file, deleted the contents. Closed and reopened the terminal and history does not exist now. – anshupitlia Nov 16 '15 at 5:22

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.