Terminal commands without history.

Posted on : 22nd Feb 2018

The key to problem is HISTCONTROL variable. HISTCONTROL is an environment variable which is set by default in almost every Linux distribution.

If you do not wish to log the commands you are executing, start your command with space; this way it wont be included in history.

Example :  ls -al

But, this will only work when your HISTCONTROL variable is set to ignorespace or ignoreboth. To check current value for HISTCONTROL :

$ echo $HISTCONTROL
and, to set HISTCONTROL for a terminal session :
$ export HISTCONTROL=some-value
and, to set HISTCONTROL to some value for every terminal session, find/add HISTCONTROL variable in ~/.bashrc file, and set it to some value.

HISTCONTROL variable can have three values; ignoredups , ignorespace , ignoreboth.

ignoredups : When set to this value, you can ignore duplicate commands from entring your .bash_history file.

ignorespace : When set to this value, you can ignore commands starting with a space from entring your .bash_history file.

ignoreboth : When set to this value, you can ignore duplicate commands from entring your .bash_history file as well as the ones starting with a space. In short, ignoreboth acts like ignoredups+ignorespace

© 2021, All Rights Reserved · Vipin Joshi