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
add comment

1 Answer

up vote 16 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

HISTCONTROL=ignorespace

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

history

to display the list of commands in your history. Find the number next to the one you want to delete and run

history -d $num
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
    
That perfectly helped :) –  mtk Oct 21 '12 at 10:24
1  
@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
show 2 more comments

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.