10 Awesome Linux cd Command Examples

10 Awesome Linux cd Command Examples

10 Awesome Linux cd Command Examples: The Linux cd command, cd stands for change directory is a Linux command line utility for navigating to file system. The Linux cd command is a basic command but most frequently used command Linux system.

While navigating through the directory structure you should clear about uses of the absolute path and relative path in the hierarchy.

  • Absolute Path is the full path of directory and always starts with / in Linux system. For example: /tmp, /usr/bin, /var/www etc.
  • Relative Path is the partial path of any directory or subdirectory. It can be started from any location of file path except /. For example: www, ./script.sh, ../../www etc.

Now you must memorize these symbols and special characters use the cd command. What’re the symbols meaning when used with the cd command.

  • Single dot (.) : current directory (present directory).
  • Double dot (..) : parrent directory.
  • Tiled (~) sign : home directory of current users.
  • $HOME variable: home directory of current users.


The cd command uses following syntax.

$ cd /path/to/directory

Read More: Linux mkdir Command Help and Examples

10 Awesome Linux cd Command Examples

Go through the following examples and understand the working of cd command in Linux. Read all examples one by one and understand how to navigate in the directory structure with the cd command.

Change to specific directory

For example you want to change to /tmp directory. Type cd followed by /tmp to navigate to that directory. FYI – /tmp is here absolute path which is starting with /.

mathan@linuxmasterswiki:~$ cd /tmp

To find your current directory use pwd command. It shows present working directory.

mathan@linuxmasterswiki:/tmp$ pwd

Output of above command

Change to other directory with cd

Type cd followed by /var/www to navigate to that directory. There is no need to go to the root directory.

mathan@linuxmasterswiki:/tmp$ cd /var/www

Change to last working directory

You can switch to your last working directory using the hyphen (-) in place of directory location.

mathan@linuxmasterswiki:/var/www$ cd -

Change to users home directory

The ~ symbol referred to users home directory. Switch to users home directory type cd followed with ~.

mathan@linuxmasterswiki:/var/www$ cd ~

You can also use HOME environment variable to switch to users home directory.

mathan@linuxmasterswiki:/var/www$ cd $HOME

Change to one level up directory

For example you are in /var/www/html directory. Now switch to /var/www either using absolute path (/var/www) or your can use double dot (..) to switch to one directory up.

mathan@linuxmasterswiki:~$ cd /var/www/html   
mathan@linuxmasterswiki:/var/www/html$ cd .. 
mathan@linuxmasterswiki:/var/www$ cd .. 

Change to multiple level up in directory structure

For example your are in the following directory location.


Now switch to one level up from the current directory, which is themes.

mathan@linuxmasterswiki:/var/www/linuxmasterswiki.com/public/wp-content/themes/extra$ cd .. 

Now switch to the public directory, which is two level up from the current directory.

mathan@linuxmasterswiki:/var/www/linuxmasterswiki.com/public/wp-content/themes$ cd ../..   

Swith to directory /var with is three level up from the current directory.

mathan@linuxmasterswiki:/var/www/linuxmasterswiki.com/public$ cd ../../.. 

Change directory with relative path

For example your are in the following directory location.


Now switch to another directory location available at /var/www/example.com/public/. You can see that /var/www is common with the present path.

mathan@linuxmasterswiki:/var/www/linuxmasterswiki.com/public$ cd ../../example.com/public

Use physical directory instead of symbolic link

For better understanding creating a demo directory structure, Create a symbolic link

mathan@linuxmasterswiki:~$ mkdir -p /var/www/example.com/public
mathan@linuxmasterswiki:~$ ln -s /var/www/example.com/public  /var/www/public
mathan@linuxmasterswiki:~$ ls -l /var/www/public

lrwxrwxrwx 1 root root 27 Jun 27 15:51 /var/www/public -> /var/www/example.com/public

Now switch to symbolic link /var/www/public directory with cd.

mathan@linuxmasterswiki:~$ cd  /var/www/public  

You find that its showing the symbolic link name in file path. The pwd command will also show the same.

Now use -P option with the same command.

mathan@linuxmasterswiki:~$ cd -P  /var/www/public  

You can see that -P forces the cd command to follow the actual directory path instead of symbolic link path.

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

Enjoyed this video?
10 Awesome Linux cd Command Examples
"No Thanks. Please Close This Box!"