Unix / Linux: Bash Shell Disable History Logging

Objective: Disable command line history logging in bash shell.

Bash has a few environment variables to control how commands are saved to the history list. They are:

  • HISTCONTROL: If the value includes ‘ignorespace‘ or ‘ignoreboth‘, then lines which begin with a space character are not saved to the history file.
  • HISTFILE: Points to the location of the history file. By default it is ~/.bash_history. If this is unset, command history is not saved.

So, to disable selective commands from being saved to the history file list, initialise HISTCONTROL variable to ignorespace or ignoreboth in the .bashrc file in your home directory.

Once done, logout and login to the shell for the changes to take effect. Then to prevent sensitive commands from being saved to the command history file, use the following syntax – add a space before entering the command.

To prevent the shell from writing all commands executed within an interactive shell to the history file, just unset the HISTFILE environment variable.

In this way, the interactive shell will not update the history file when it exits.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }