When I give sudo -i, the terminal does not display the current folder correctly

Every time I change to root in the terminal, the directory is changed to /root instead of continuing with the current one. See below:

root@MaylaVettel-PC2:/home/mayla99654/Área de Trabalho/xdm-setup-7.2.11# ls
install.sh readme.txt
root@MaylaVettel-PC2:/home/mayla99654/Área de Trabalho/xdm-setup-7.2.11# cd
root@MaylaVettel-PC2:~# ls
snap
root@MaylaVettel-PC2:~# pwd
/root
root@MaylaVettel-PC2:~#

As you can see, every time I go to root (inside a directory), it takes me out of the current directory and sends me to /root. When I'm in root, and I give the command cd, it takes me to ~ (which is not my /home) and when typing ls, it shows me the files/folders of /root directory. Confused. But it is as if the default directory is set to /root.

Can anyone give me a help for this problem?

Yes, that is normal. When you use sudo -i, this opens the terminal in Root at root directory.
You can instead use sudo -s to open the current working directory as Root.

Some file managers (mine does) allows a Right Click menu option for "open in Root" or "Open with Administrator Privileges" which will open the terminal as Root in the current directory. I use Nemo File Manager and it does this.
Otherwise, if you go root in terminal with "sudo -i", you can use "cd" command followed by the full accurate path back to the directory you want.

1 Like

Weird. I thought I did something wrong, because... I thought the default root folder was /home yet, and not /root.

Default Root in terminal for sudo -i goes right to / Root. But the command sudo -s should serve your need. :slight_smile: