How to disable bash shell history in Linux

I do not want to save root users’ shell history. How do I force Linux or Unix server to forget bash shell history? How to disable bash shell history on Linux for the root user?

The bash shell saves commands entered from terminal to a history file. You can recall the list of commands previously typed. The history command displays bash commands that you executed prior. These commands make up your command history. By default, history shows a numbered list of the 500 most recent commands, from earliest to most recent. The value of the HISTSIZE variable is used as the number of commands to save in a history list.

ADVERTISEMENTS

How to display current history

Just type the history command:
history
history | less
history | more
history | grep 'find'

How to find out the number of commands saved in history

Use echo command or printf command :
echo "$HISTSIZE"
OR
printf "%d\n" $HISTSIZE
Sample outputs:

1000

The value of the HISTSIZE variable indicates that the 1000 number of commands saved in a history list.

Where are my bash history commands stored

The history is initialized from the file named by the variable HISTFILE. The default is ~/.bash_history file. To view current settings run:
echo "$HISTFILE"
OR
printf "%s\n" "$HISTFILE"
Sample outputs:

/home/vivek/.bash_history

How to disable BASH shell history on Linux or Unix

You can remove HISTFILE shell variable by typing the following unset command:
unset HISTFILE
Add above line to the end of to a new /etc/profile.d/disable.history.sh file or ~/.bash_profile:
echo 'unset HISTFILE' >> /etc/profile.d/disable.history.sh
OR
echo 'unset HISTFILE' >> ~/.bash_profile

How to permanently disable bash history using set command

Another option is to pass the +o history option to the set builtin command:
set +o history
Again add set +o history to the end of to a new /etc/profile.d/disable.history.sh file or ~/.bash_profile. See how to set and use shell option in bash for more info.

How to clear the bash history

Type the following command in your current session:
history -c
To delete a single command number 42 from history in Linux/Unix:
history -d 42
How to disable bash shell history on Linux
See “A Shell Primer: Master Your Linux, OS X, Unix Shell Environment” for more info.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS

Comments on this entry are closed.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.