Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm working in Mac OSX, so I guess I'm using bash...?

Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?

share|improve this question

2 Answers 2

up vote 43 down vote accepted

Preventative measures

If you want to run a command without saving it in history, prepend it with an extra space

prompt$ echo saved
prompt$  echo not saved \
> #     ^ extra space

For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run


To make this setting persistent, put it in your .bashrc.

Post-mortem clean-up

If you've already run the command, and want to remove it from history, first use


to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run

history -d 1234
share|improve this answer
It worked. I think we need to source ~/.bashrc after modifying it... –  B Seven Sep 26 '12 at 18:00
@BSeven Yes, all bash settings are stored in RAM while the shell is running. The rc files are only for storing persistent settings for the next time the shell starts. –  jw013 Sep 26 '12 at 18:03
There are edge cases when this will not work, but under default configurations it should. –  jordanm Sep 26 '12 at 19:27
@jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088 –  jordanm Oct 22 '12 at 3:54
@Moberg $num is a shell parameter (a.k.a. variable). I can see how my example would be confusing if you didn't know about shell parameter expansion, so I edited the code to use a concrete example instead. –  jw013 Aug 26 at 13:05
  1. To clear all your history, use

    history -c
  2. To delete a single line, use

    history -d linenumber
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.