Disable Current Shell Session Input History

Sometimes you need to run commands that shouldn’t persist in your shell history; credentials, sensitive commands, or one-off experiments on remote machines.

Bash keeps an in-memory history of commands and normally saves it to HISTFILE when the shell exits. Some setups also write history after each command using history -a. What you see with history may already be on disk.

To stop this shell from saving further history to its usual file, unset HISTFILE before running sensitive commands. This does not remove anything already saved.

unset HISTFILE

A better option would be ignoring or deleting a specific line. To avoid saving individual commands to the input history, prepend a blank space before each command. To do this we need to set HISTCONTROL to ignorespace.

export HISTCONTROL=ignorespace

To delete a specific entry from this shell’s in-memory history:

history -d <history-number>

Use unset HISTFILE before a sensitive session and HISTCONTROL=ignorespace for selective exclusion during normal work. history -d only removes an entry from the current shell’s in-memory history; it does not erase an entry already written to disk.

None of these methods removes commands from other shells, audit logs, or terminal recordings. Avoid putting credentials directly on the command line; if a secret has been exposed, rotate it.

All writing →