Wednesday, May 8, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  49] [ 0]  / answers: 1 / hits: 137193  / 1 Year ago, fri, march 24, 2023, 10:56:32

I'm not talking about .bash_history from my home directory. I usually prefer to use sudo -i or sudo su and then run commands as root user.



Since, after these commands the history is not saved in the .bash_history file from my home directory, I want to know if this history is saved somewhere or not and if yes, where?


More From » bash

 Answers
0

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

[#26046] Sunday, March 26, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antoccasiona

Total Points: 430
Total Questions: 127
Total Answers: 131

Location: Netherlands
Member since Sat, Jun 26, 2021
3 Years ago
antoccasiona questions
Sat, Oct 23, 21, 22:34, 3 Years ago
Sat, Sep 24, 22, 09:39, 2 Years ago
Sun, Jan 15, 23, 11:08, 1 Year ago
;