There is sometimes a situation when you want to run some command in terminal but you don’t want to see that command in bash history – and that commands usually contains passwords or some confidential information – for which you would not want to be seen if someone logs on to a server with the same login data.
History is very important thing in Linux because you have an overview of what has been done before in terminal – sometimes you may need to replay commands from history what is OK, but sometime you need to delete something from it (well – if you screw-up something), forbid the preservation of history, and similar ‘nasty’ things.
In short lines – the variables which begin with HIST are related to history in Linux (HISTSIZE, HISTFILE, HISTCMD, HISTCONTROL, HISTTIMEFORMAT, HISTIGNORE) and if you want to change something on ‘history level’ – you need to change that variables. In our situation – when we want to keep ourself’s from history logging of our commands – we will play with HISTFILE variable. HISTFILE variable is related to file location where your history is saved so if you run: echo $ HISTFILE, you will see where the history file is located. So – if you want to hide your commands while you are logged in – but on session level (when you reconnect – history will be ON) run this:
unset HISTFILE # or HISTFILE=/dev/null # or HISTFILE=
If you want to delete something from your current bash history, you can do it with combination of unset and your favorite editor, for example:
unset HISTFILE vim .bash_history
If you want to keep out your commands out of history always – just put unset in your .bash_profile file.
echo "unset HISTFILE" >> ~/.bash_profile ; . ~/.bash_profile
Of course – delete this unset line from your bash_profile if you want to return logging to history.