Could someone give me an explanation of the difference between
cd / and
Also, what is the difference when using the same command at administrator level?
cd / changes the directory to root of the filesystem, which is
cd ~ changes it to your home directory.
~ is interpreted as the home folder of the user who is executing the command. For me it is
If you run
cd ~ as root, that will change the working directory to root users home, which is at
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.
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.
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.