Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
That I know but I wanted to know the commands inside the root shell and I have found my answer. – Devesh Khandelwal Apr 13 '14 at 16:28
I knew that but still thanks. – Devesh Khandelwal Apr 13 '14 at 16:31
up vote 11 down vote accepted

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
share|improve this answer

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.

share|improve this answer
I know about the up key and use it a lot. What I wanted was the complete history file and thank you for clarifying. – Devesh Khandelwal Apr 13 '14 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 '14 at 16:38
Ok, Thank You... – Devesh Khandelwal Apr 13 '14 at 16:39

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*
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.