Is there a way to temporarily suspend history tracking in bash, so as to enter a sort of "incognito" mode? I'm entering stuff into my terminal that I don't want recorded, sensitive financial info.
This should be what you're looking for:
If HISTFILE is unset, or if the history file is unwritable, the history is not saved.
Alternatively, if you want to toggle it off and then back on again, it may be easier to use
set +o history
set -o history
Make sure that
ignorespace. You'll probably want to add
HISTCONTROL=ignoredups:ignorespace or something) to your
~/.bashrc. Then any command line that begins with a space is omitted from the history.
Another possibility is to start a new bash session that doesn't save its history.
$ bash $ unset HISTFILE $ sooper-sekret-command $ exit $ #back in the parent shell
If you need to avoid storing several commands and you still want to use up arrow to access previous commands, use:
$ bash # open a new session. $ unset HISTFILE # avoid recording commands to file. $ commands not recorded . . $ exit $
There are four ways (levels) to control how commands are stored.
The first and simplest is to use
That will allow to use an space before the commands that you want to avoid being recorded in the memory list of
history. And, in consequence, as there is no command recorded in memory that could be sent to file, will also avoid one command to be sent to the file listed in
Avoid recording commands to the file in
$ unset HISTFILE
If unset, the command history is not saved when a shell exits.
HISTFILE=''and/or set to
HISTFILE=/dev/nullworks to the same effect. Understand that commands are still being recorded to the memory list , try the
historycommand, or the up arrow.
Warning: if HISTFILE is reset before the shell exists, all what has been recorded in memory could be written to the file anyway.
Avoid recording new commands to the history list in memory. And, as not being in memory, can not be recorded to file.
$ shopt -ou history # or set +o history
shopt -os history(or
set -o history)
Remove all commands from to the history list in memory:
All commands get erased (from memory) and therefore nothing could be stored to file, of course, until the variable is set again to some valid numeric value.
There is one simple way to turn off the history, so commands won't be stored in the
You have to put the whitespace or tab space in front of any command, so that command won't be stored in the history. For example:
$ ls print the list of file $ history ls history $ pwd print the current working directory $ history ls history
pwd command will not get store in the history, because it has whitespace in the front.