Share via:

CD Command

How to change directories using the terminal in Linux.


Edited: 2017-04-29 22:35

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:

cd /var/www

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 /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:

cd ../../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 reference

cdMoves you to the Login directory (/home/MyUser).
cd ~Login Directory (/home/MyUser)
cd /home/MyUserChanges directory using absolute path.
cd ../../homeChanges directory using relative path.

See also: Absolute and Relative Paths