Could someone give me an explanation of the difference between cd / and cd ~

Also, what is the difference when using the same command at administrator level?

  • 1
    You can also just cd with no arguments and it will go home, just like cd ~ if you get tired of pushing those extra buttons for this common use. – Jeff Puckett Oct 28 '16 at 12:13

cd / changes the directory to root of the filesystem, which is /

while cd ~ changes it to your home directory.

Here ~ is interpreted as the home folder of the user who is executing the command. For me it is /home/anwar.

If you run cd ~ as root, that will change the working directory to root users home, which is at /root. root users home folder does not typically reside under /home/ directory, instead it is found directly under root directory /.

Check this question for a general introduction to Linux Filesystem


Please note: In the original question, the paths are not the same, and those commands are not equal.

cd /

This changes to the / (root) directory of the system. It's a hardcoded path, and will go to the same directory no matter what user executes it.

cd ~

This is a shell shortcut that always references the user's home directory.

If user "raj" executes cd ~, and their home directory is /home/raj, it will take raj to /home/raj.

If user "babna" executes cd ~, and their home directory is /home/babna, it will take babna to /home/babna.

If the same command is executed as root, it will take you to /root on a typical Ubuntu system.

This is very useful for scripting, since multiple users can use the same script and affect changes to their home directory.

For single commands input manually into bash, so long as the paths end up the same, it doesn't matter how they're input, since cd itself is a shell built-in which will use the same mechanism to switch directories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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