Changing the directory in Linux can be done with the CD command. The command is the same as that in DOS, and also works with relative paths.
To change to your www directory, if you are running a web server, you can simply type:
When you are logged in as your user, the default directory will be your home directory. To move back to home after changing directory, you can simply type either of the below commands:
cd cd ~ cd /home/MyUser
If your location is in some subdirectory, you may also use relative path to change directory. For instance, assuming your current location is /var/www/MySite, using the below relative path would change your location to /var/log:
If you attempt to change to a directory you do not have permissions to view, you will get an error like the below:
bash: cd: /root: Permission denied
To avoid this error you need to use sudo or su, alternatively you can also change to the root user.
|cd||Moves you to the Login directory (/home/MyUser).|
|cd ~||Login Directory (/home/MyUser)|
|cd /home/MyUser||Changes directory using absolute path.|
|cd ../../home||Changes directory using relative path.|
See also: Absolute and Relative Paths