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.
-
4You might be interested in serverfault.com/questions/48769/…Luc M– Luc M2012-02-23 17:50:45 +00:00Commented Feb 23, 2012 at 17:50
3 Answers
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.
-
7space is how I've always done it.Rob– Rob2012-02-23 15:31:20 +00:00Commented Feb 23, 2012 at 15:31
-
I used to accidentally enter additional
y, after allcp(aliased tocp -i) get over. So I aliasedyasalias y='$(history | awk '"'"'END{if(NF==2 && $2=="y"){print "history -d " $1}}'"'"')'... ButHISTIGNOREis better method as it looks. :) Thanks.anishsane– anishsane2013-11-22 13:02:06 +00:00Commented Nov 22, 2013 at 13:02 -
2Just to be more explicit: you can add
export HISTCONTROL="ignorespace"to your~/.bashrcto ignore commands that start with spaces.Aidan Feldman– Aidan Feldman2016-06-12 02:20:41 +00:00Commented Jun 12, 2016 at 2:20 -
@AidanFeldman not default on macOSakauppi– akauppi2017-10-12 16:28:44 +00:00Commented Oct 12, 2017 at 16:28
-
NOTE: space should be included when we type in the commandline and not in HISTIGNORE.Gayan Weerakutti– Gayan Weerakutti2018-03-27 05:58:36 +00:00Commented Mar 27, 2018 at 5:58
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.
-
8Depends on
$HISTCONTROL(see my answer).l0b0– l0b02012-02-29 09:48:39 +00:00Commented Feb 29, 2012 at 9:48
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 :-)
-
3
-
1I used to do this. but setting
HISTFILE=/dev/nullis a better option.anishsane– anishsane2013-11-22 12:54:01 +00:00Commented Nov 22, 2013 at 12:54 -
1simply
HISTFILE=works in both bash and ksh.kubanczyk– kubanczyk2016-04-08 18:45:36 +00:00Commented Apr 8, 2016 at 18:45 -
2or
unset HISTFILETodd Walton– Todd Walton2018-11-29 16:35:14 +00:00Commented Nov 29, 2018 at 16:35