Linux cd Command Tutorial with Examples

The cd command is used to change the current working directory and navigate between different directories. The cd is the short form of the change directory term. The cd command is one of the most used commands in Linux distributions.

cd Command Syntax

The cd command has the following simple syntax.

  • OPTIONS is used to provide different options. The OPTIONS parameter is optional.
  • PATH is used to navigate to the specified path which can be relative or absolute. This PATH parameter is optional.

Current Working Directory

Before starting the examples of the cd command for navigation on the command line we should learn. The current working directory or current working path is the active path where the specified command will run. Before changing the current working directory we can display the current working directory. The pwd command is used to

$ pwd

The output will be the complete path of the current working directory like below.


Absolute Path and Relative Path

In Linux, paths can be specified in two forms. The absolute path is the path specification where the complete hierarchy of the path is provided completely by starting from the root directory. Below you can see some absolute path examples.





The cd command can be used with the absolute path like below.

$ cd /etc/security/
$ pwd

$ cd /home/ismail

$ pwd

The relative path is expressed as related to the current working directory or parent directory using double dots.



The relative path can be used to change directory and navigate to the other directories. In the following example we will navigate to the current working directory Downloads folder and DEBIAN folder.

$ cd Downloads/DEBIAN/

Navigate To Parent Directory

The bash terminal provides the double dots or .. in order to specify one level upper directory which is called parent directory. For example, the following cd command with double dots will navigate to the one-level upper directory which is /home/ismail .

$ cd ..

We can also use the double dots multiple times in a single path. In the following example we will navigate to the 3 level upper directory.

$ cd ../../../

The double dots can be also used with the directory names together where double dots will be used go upper directories and directory names will be used to go down to child directories.

$ cd ../ismail/../

Navigate To Previous Directory

The cd command provides the dash character, as an parameters. The dash is used to specify the previous directory which can be a parent, child or unrelated directory.

$ cd -

Navigate To Home Directory

Linux users have home directories in order to store personal files and folders. The home directory is generally located under the /home . The tilda ~ can be used to specify the current user home directory. For example, if the current user is ismail the ~ will be /home/ismail . Tilda can be used with the cd command easily.

$ cd ~

We can also use the tilda with child directories like below.

$ cd ~/Desktop

Also, another user’s home directory can be navigated by using the tilda and user name. In the following example, we will navigate to the ahmet home directory.

$ cd ~ahmet
READ  How To Exit From Vim?

Leave a Comment