Where is the bash history for the root user saved?

Well, when you're logged in as root, the bash history is saved in /root/.bash_history file, where /root is the default home directory for root user. To prove this, run the following command when you are logged as root:

echo $HISTFILE

The $HISTFILE variable points to the file that contains your history.

Source: $HISTFILE

Generally when you log into another user account, the bash history will be saved in a file called .bash_history located in the home directory of that user.

Furthermore, if you want to save the bash history for the root user in another file, let say in .bash_history file from my home directory, you have to edit /root/.bashrc file, and add a new line at the end of file with the following content:

HISTFILE="/home/username/.bash_history"       #change username with your user name

Tags:

Bash