Updated by Linode
Written by Linode
What is cd?
On Linux systems,
cd is a command that changes the directory you are in when working in the terminal.
cd is one of the most used commands in Linux and has several shortcuts as well as two options.
To change directories using
cd [option] [directory]
For example, to navigate to the directory
/usr/local, you would use the following syntax:
In the previous example an absolute path name was used. However you can also use a path relative to your current location. For example, if you are in
/usr/local and want to change into
/usr/local/share, you can do so with the following relative path:
Shortcuts in cd
Several shortcuts are available for
cd which makes navigating between directories quicker and easier.
To navigate to the parent directory relative to where you are currently, use two consecutive dots (
These dots can also be stacked to move up multiple levels:
To change into the root directory, no matter your current location, use a forward slash
To change into your home directory, no matter your current location, use a tilde
You can also change into your home directory by using
cd without any arguments:
To change to the last location, use a hyphen
This shortcut is helpful to toggle between two locations with long absolute paths to type. Note that it also returns the last location’s absolute pathname.
Options in cd
cd has two options,
-L option forces symbolic links to be followed. This means if you tell
cd to change into a directory that is a symbolic link, it will follow it and move you into the directory it’s pointing at instead of the directory specified. This is the standard behavior of
cd and does not need to be specified. For example, if you want to change into
/var/example.com but that’s a symbolic link to
/var/www/example.com by issuing the following command, you will change into
cd -L /var/example.com
-P option tells
cd to use the physical directory structure and not to follow symbolic links. If you use this option, instead of navigating to where the symbolic link points to, you will change into the physical directory, if it exists. If the directory does not exist, the system will alert you with a
directory does not exist error and you will remain in the current directory. For example, say you want to
cd to a symbolic link
/var/example.com that points to
/var/www/example.com, you will simply change into the directory and not follow the link:
cd -P /var/example.com
-Pare specified, the
-Poption will be ignored.
This guide is published under a CC BY-ND 4.0 license.