2

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?

0

1 Answer 1

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" 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.