How can I run a shell command without being added in history? I don't want to purge the command history, I just don't want my next shell command doesn't show up in the history. Is this possible?
Asked
Active
Viewed 118 times
1 Answers
3
In bash
, to prevent a command from being added to history, put a space before the command. This is assumes that you have, as is common, the ignorespace
option set in HISTCONTROL
. If you don't, run the following command (or add it to ~/.bashrc
to make it permanent):
export HISTCONTROL=ignorespace
Many people also want to ignore duplicate commands, in which case use:
export HISTCONTROL=ignoredups:ignorespace
If you want to ignore certain commands always, then use HISTIGNORE
. For example, the following setting will always ignore sudo poweroff
, sudo shutdown
followed by any options, and sudo reboot
:
export HISTIGNORE="sudo poweroff:sudo shutdown*:sudo reboot"

John1024
- 74,655