Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

2 Answers 2

up vote 9 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 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.

share|improve this answer
1  
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 terminal.app 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

Your Answer

 
discard

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.