1

When I use the command sudo -i and input the password, and then input ls, I found that I can only see the Desktop folder and packages in terminal.

But when I came back to normal mode, all the folder showed up.

I don't know what cause this problem...Can someone help me ?

2
  • 1
    If you want your home directory while root you have to do cd /home/user/Desktop
    – troylatroy
    Oct 31, 2013 at 17:15
  • Oh my god...Thanks! Your answer solve my problem!
    – brandboat
    Nov 1, 2013 at 1:03

3 Answers 3

7

The sudo -i command gives you a shell as root, and you will be in the root user's home directory, not your own. As root is not generally a user you should use normally, only very few files will exist in the home directory for that user, particularly the skeleton directory structure for any new user.

0
3

It is because when you are in root mode you are in root's home directory. Try this:

pwd
sudo -i
pwd

You will see the directory change

0
1

this was troubling me too much also, so I made this script:

params="$@";sudo -i bash -c "cd \"`pwd`\";$params"

pwd will be run with your normal user, before the command you want

put it on a script file which is root:root rw-r--r-- on a folder full hierarchy owned by root too like /MyScripts (create it) to be safer..

the flaw on it is if you have a parameter with a space in-between like ls -1 a "b c", would require to be ls -1 a "b\ c", but this can be worked out later when you improve the script :)

You must log in to answer this question.

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