Terminal 'incognito mode'?

Run a command without putting it in history:

Simply put a space before the command. Bash will ignore commands with a prepended space:

Example: Spaceecho "Some secret text"

Note: This only works if the HISTCONTROL variable is set to ignorespace or ignoreboth.


Disable history temporarily:

  • Run Spaceset +o history or Spaceshopt -uo history to disable history.
  • Run set -o history or shopt -so history to enable it again.

Disable history for the current session (won't remember any commands from the session):

unset HISTFILE

Note: You'll be able to see the commands pressing Up until you close the terminal.


Remove a command from the history:

Run Spacehistory | grep "part of your secret command"

It will show a list of previously ran commands, in this format:

user@host:~$  history | grep pkill
  302  pkill $$
  467  pkill gone-cal
  468  pkill actionaz
  500  pkill chrome
  550  pkill super

Select the entry number at the left of the command. You can copy it with Ctrl+Shift+C

Run Spacehistory -d <number> where <number> is the entry number to remove the entry.
You can paste that number with Ctrl+Shift+V


Other interesting answers:

  • @echristopherson
  • @MoithilBiswas
  • @dolt

You can simply delete the history of one particular terminal session by adding command history -cw after working.

Do not close the terminal before giving this command.


shopt -uo history should do it best.

Nuking the HISTFILE (et al) variables won't stop your Up history being logged, it just won't push it to disk. This may or may not be a positive thing for you, but given you mention it, I guess you want something better. Changing the shopt history setting stops the whole history mechanism from triggering.

You can turn logging back on with shopt -so history (the -s and -u are set and unset respectively).

Note that the command itself will probably be logged so prepend it with a space to stop it being added to the history before you clear the variable.