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?

  • That I know but I wanted to know the commands inside the root shell and I have found my answer. Apr 13, 2014 at 16:28

3 Answers 3


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:


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


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

Typing history on the shell list the all the commands in the history. One can use the following command to save history to another file:

history > *textfile*

I'm used to using the shortcut list via the up key on the keyboard which shows the last used command for that user. If you log in as root then you will be shown the history for the root user.

Test it like this, sudo -i fill in the password and then hit the up key on the keyboard. Now you will scroll through the last used commands in the order recent to oldest.

I know Radu Rădeanu answer is what you wanted. But this also solves the problem at hand. My solution is more of a handy way of remembering an old command which may save time and hustle.

  • I know about the up key and use it a lot. What I wanted was the complete history file and thank you for clarifying. Apr 13, 2014 at 16:35
  • @DeveshKhandelwal It's not the solution you wanted but someone else might find it useful. Radu's answer is good this is just a different one. :)
    – Alvar
    Apr 13, 2014 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .