1. Insert space before command
Insert a space in the beginning of a command, and it will be ignored by the shell, meaning the command won’t be recorded in history. However the said solution will only work if the HISTCONTROL environment variable is set to “ignorespace” or “ignoreboth,” in ~/.bashrc file.
Ex:
echo "command 1"
echo "command 2"
echo "command 3"
[space]echo "secret command"
history
[space]echo "secret command" Won’t appear in the history if you’ve already done this command:
export HISTCONTROL = ignorespace
Disable the entire history for the current session
If you want to disable the entire history for a session, you can easily do that by unsetting the HISTSIZE environment variable before you start with your command line work.
To unset the variable run the following command or put it on ~/.bashrc file:
HISTSIZE=0
- HISTSIZE: number of lines (or commands) that can be stored in the history list for an ongoing bash session.
- HISTFILESIZE: Tamanho máximo em bytes (B) que o arquivo será permitido atingir:
source ~/.bashrc
Erase the entire history after you’re done
This can be seen as an alternative to the solution mentioned in the previous section.
The only difference is that in this case you run a command AFTER you’re done with all your work. Thh following is the command in question:
history -cw