17

I searched now a while but couldn't find an answer to this question.

I have a Linux based server (centOs).

In the root folder (/) i have a folder called root (/root).

Now when I sudo cd root/ i stay in the same folder (/).

First I thought that /root is a symlink but symlinks are cian blue and here I have dark blue.

I've read that the /root folder is the root user folder but I don't get in it.

Can somebody please explain what is going on here?

3
  • 1
    cd is a builtin shell command, so doing sudo cd /root won't work (and you'll get an "command not found" error). You need to use a shell as root to use what's there (su - for instance) or do sudo ls -a /root if you want to see what's there.
    – cylgalad
    May 2, 2016 at 8:31
  • Thanks a lot that worked, but i didn't get an error message. May 2, 2016 at 8:36
  • @OlivierKrull, Please see What should I do when someone answers my question ? May 27, 2018 at 15:46

3 Answers 3

21

/ (Root directory) vs /root directory

  1. / directory called as Root Directory sits on the top of the file system hierarchy.
    • That means it is the ultimate parent or grandparent or grand grandparent of any file or directory you can find on your system.
    • It contains all the files necessary for the system to work such as boot files, libraries, packages, essential binaries, system configuration, user files and temporary files.

Linux file system source

  1. Now /root is the Home directory for User named Root. See at the bottom right in above image.

    • Just like every User has it's own directory with his/her username under /home, User Root must have also a directory.
    • But Since Root user needs to know every tiny detail about system, so his home directory is created under / itself by the name /root
    • It contains the files and folders you created when you were root user and also the hidden configuration files for some applications or packages you installed.

Now when I sudo cd root/ I stay in the same folder (/)

As pointed by cylglad in the comments,

cd is a builtin shell command, so doing sudo cd /root won't work

See this :

amit@C0deDaedalus:~$ cd /root
bash: cd: /root: Permission denied
amit@C0deDaedalus:~$ 
amit@C0deDaedalus:~$ sudo cd /root
[sudo] password for amit: 
sudo: cd: command not found

Instead you have to first change to root user, then do a cd to /root

$ sudo -i
# cd /root
# pwd

Feel free to add in more details.

0
1

change to the root user and then CD to it

$ sudo su
# cd /root

as was previously mentioned, cd is a bash built-in and can't be executed using sudo. if you want to see the permissions on a directory, try

$ ls -al

then look at the permission column to determine if the user you are logged in with has permissions.

3
  • 3
    sudo -s / sudo -i / su / su - , but not "sudo su"
    – Tom Yan
    May 3, 2016 at 4:13
  • @TomYan why not sudo su? It is effectively sudo -i. A root password is not always set and su by itself will not work in those cases.
    – Iyad K
    May 3, 2016 at 9:29
  • 1
    for it's silly and unnecessary (and other possible issues)
    – Tom Yan
    May 3, 2016 at 16:59
0

Your root folder is /. Your /root is the root's home folder. For instance if you create a user called test, then it's home folder is /home/test. For root user, it is simply /root instead of /home/root.

1
  • Yes i already understood this. But when i want to get inside the /root directory i stay in (/). May 2, 2016 at 8:26

You must log in to answer this question.

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