Start your command with a space and it won't be included in the history.
Be aware that this does require the environment variable $HISTCONTROL
to be set.
Check that the following command returns ignorespace
or
ignoreboth
:
echo $HISTCONTROL
To add the environment variable if missing, the following line can be added to the Bash profile. E.g., to file %HOME/.bashrc
.
export HISTCONTROL=ignorespace
After sourcing the profile again, space-prefixed commands will not be written to $HISTFILE
.
In any given Bash session, set the history file to /dev/null by typing:
export HISTFILE=/dev/null
Note that, as pointed out in the comments, this will not write any commands in that session to the history!
Just don't mess with your system administrator's hard work, please ;)
Doodad's solution is more elegant. Simply unset the variable: unset HISTFILE
(thanks!)
echo "discreet";history -d $(history 1)
An extension of John Doe's and Cédric ROYER's answer. But, this seems to work for me.
<your_secret_command>; history -d $((HISTCMD-1))
You should not see the entry of the command in your history.
Here's the explanation...
The 'history -d' deletes the mentioned entry from the history.
The HISTCMD stores the command_number of the one to be executed next. So, (HISTCMD-1) refers to the last executed command.
Remove a certain line from Bash history file
You might consider using a shell without history, like perhaps
/bin/sh << END
your commands without history
END
(perhaps /bin/dash
or /bin/sash
could be more appropriate than /bin/sh
)
Or even better, use the batch utility, e.g.,
batch << EOB
your commands
EOB
The history would then contain sh
or batch
which is not very meaningful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With