Changing the Directory in Linux | cd Command

Last Updated : 9 Jan, 2026

The cd (Change Directory) command in Linux is used to navigate between directories in the file system.

  • It allows users to move from the current working directory to another specified directory by providing either an absolute path or a relative path.
  • This command is essential for exploring different locations within the Linux environment and managing files efficiently.

Examples:

Here are some commonly used examples of the cd command in Linux.

1. Move Inside a Subdirectory

To move inside a subdirectory in Linux use the CD Linux Command. Here, replace [directory_name] with the desired directory you want to move in.

Syntax:

cd [directory_name]

Example:

cd Documents

1--CD-Documents

Here, we have used the following commands:

  • `ls` = To display all the files and directories in the current location (directory)
  • `pwd` = to check the current location path or we can say the current directory name

2. Using `/` as an Argument

Using / as an argument with the cd command changes the current directory to the root directory, which is the topmost directory in the filesystem hierarchy.

cd /

2--CD-Slash

Above, / represents the root directory. and used `pwd` to check the current location path or we can say the current directory name.

3. Move Inside a Directory From a Directory

This command is used to move inside a directory from a directory. Here, replace "dir_1/dir_2/dir_3" with the subdirectory name or location you want to move in.

cd dir_1/dir_2/dir_3

For Example: We are in the "/home/raghvendra" directory and we want to move to its sub-directory location (path) "Documents/geeksforgeeks/example"

cd Documents/geeksforgeeks/example

3--CD-Document-Geeks

Explanation: We have the document directory and inside the document directory we have a directory named geeksforgeeks and inside that directory, we have an example directory. To navigate the example directory, we have used the command cd Documents/geeksforgeeks/example.

4. Change Directory to Home Directory From Any Location

`~` This argument is used in the `cd` command to change the directory to the home directory from any location in the Linux System.

cd ~

For Example: We are in location "/home/raghvendra/Documents/geeksforgeeks/example" and want to move to the home directory. We can use the following command.

cd ~

4--CD-Tilda

We can also pass the `cd` command with no arguments, which will eventually land us in our home directory.

cd

5--Only-CD

5. Move to Parent or One Level Up from the Current Directory

Use `..` this as an argument in the `cd` command which is used to move to the parent directory of the current directory, or the directory one level up from the current directory. ".." represents the parent directory.

cd .. 

For Example:

We are in location "/home/raghvendra/Documents/geeksforgeeks/example" and want to move to the parent or one level up in the directory. We can use the following command.

cd ..

6--CD-

6. Change Directory by Using DIR NAME Command

This command is used to navigate to a directory with white spaces. Instead of using double quotes, we can use single quotes then also this command will also work. Here, replace "dir name" with the directory name you want. 

cd "dir name"

For Example:

Use the command to move to "dir name" = "My songs".

cd "My songs"

7--CD-My-Song

We can also use `\` in between if we don't want to use double or single quotes.

cd My\ songs

8--CD-Slash-Song

Comment

Explore