Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable history in Linux [closed]

To disable a history in Linux environment I've executed the following commands:

export HISTFILESIZE=0
export HISTSIZE=0
unset HISTFILE

Is such command combination enough or I have to also execute history -c or something else?

Will this keep history disabled even when I reboot a server or such commands need to be executed after reboot again and again?

like image 792
Ωmega Avatar asked Sep 06 '13 17:09

Ωmega


People also ask

Which of the following commands is used to disable the bash shell from saving the history?

How to permanently disable bash history using set command. Again add set +o history to the end of to a new /etc/profile. d/disable.

Where is Linux history stored?

The background. In Bash, your command history is stored in a file ( . bash_history ) in your home directory.

What does set +o history do?

set +o history - Does not write any of the current session to the log. Can be ran at any time during the session and will hide all commands. set -o history - Turns logging back on but logs the set command so obvious something has happened.


3 Answers

For most usecases, unset HISTFILE should be enough.

That disables writing the history file, while it still allows to cycle through the last commands using up/down.
Changing HISTFILESIZE doesn't have any effect when you unset HISTFILE, as it only affects how many lines will be written to the history file when the shell exits. If set to 0 with HISTFILE set, then the file will be truncated to 0 at exit.
Changing HISTSIZE changes how many commands the current shell will remember.

To make this changes permanent, ~/.bashrc or ~/.profile are good places to insert the commands.

like image 101
mata Avatar answered Sep 22 '22 08:09

mata


Just add this command to a bash startup file which could be /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile, or ~/.bashrc depending your target scope and distro that customizes bash. See the INVOCATION section of bash's manual (man bash).

shopt -u -o history

Or

set +o history

Which would disable history.

Although you have to clear your history once:

history -c

And also delete your ~/.bash_history file.

like image 21
konsolebox Avatar answered Sep 19 '22 08:09

konsolebox


If you want it to persist through reboots, you can add them to ~/.bashrc or /etc/profile.

like image 32
OneOfOne Avatar answered Sep 20 '22 08:09

OneOfOne