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.

Is there any way to exclude commands like rm -rf, svn revert from being getting stored in bash history? Actually I, by mistake, have issued them a number of times even though I have no intent to do, just because I am doing things quickly and it happened. Hence results in lost of lots of work I have did so far.

share|improve this question
2  
You might be interested in serverfault.com/questions/48769/… –  Luc M Feb 23 '12 at 17:50
add comment

3 Answers

up vote 28 down vote accepted

You might want $HISTIGNORE: "A colon-separated list of patterns used to decide which command lines should be saved on the history list." This line in your ~/.bashrc should do the job:

HISTIGNORE='rm *:svn revert*'

Also, you can add a space at the beginning of a command to exclude it from history. This works as long as $HISTCONTROL contains ignorespace or ignoreboth, which is default on any distro I've used.

share|improve this answer
3  
space is how I've always done it. –  Rob Feb 23 '12 at 15:31
    
I used to accidentally enter additional y, after all cp (aliased to cp -i) get over. So I aliased y as alias y='$(history | awk '"'"'END{if(NF==2 && $2=="y"){print "history -d " $1}}'"'"')' ... But HISTIGNORE is better method as it looks. :) Thanks. –  anishsane Nov 22 '13 at 13:02
add comment

Though going slightly different from OP's question, when I intentionally don't want a command to get stored in bash history, I prefix them with a space. Works in Ubuntu and its variants, not sure if it works on all systems.

share|improve this answer
    
Depends on $HISTCONTROL (see my answer). –  l0b0 Feb 29 '12 at 9:48
    
@l0b0 right, thanks for pointing out. –  k4rtik Feb 29 '12 at 14:38
add comment

I usually kill my bash-instance when I have done things that I don't want in the history.

kill -9 $$

$$ represents the current process - bash when you run it from the shell. You can use $BASHPID, but that's more typing :-)

share|improve this answer
    
Some Bash settings (like this) will save the history after each command, and in that case this won't work. –  l0b0 Feb 23 '12 at 15:41
    
I used to do this. but setting HISTFILE=/dev/null is a better option. –  anishsane Nov 22 '13 at 12:54
add comment

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.