How to execute a command without saving it in .bash_history?

When I use Bash, how can I prevent a command from saving it in bash history? Well, per my tests, there are at least two ways.

1, Prepending one or more spaces to your command

With one or more spaces prepending in the command, it won’t saved in bash history file. Your command can run like this,

$ <space>command

2, Unset the variable $HISTFILE before exiting your shell

$ unset HISTFILE

This does the trick, and you can test some similar vairables like HISTSIZE or HISTFILESIZE.

Leave a comment

Your email address will not be published. Required fields are marked *