Open In App

Changing the Directory in Linux | cd Command

Last Updated : 18 Oct, 2025
Comments
Improve
Suggest changes
31 Likes
Like
Report

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.


how_to_change_the_directory_in_linux_
Changing the Directory in Linux

Prerequisites:

  • Admin Access
  • Familiar with Linux commands
  • Must know the Directory Structure (Linux Directory)

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 we use the CD Linux Command. Here, replace [directory_name] with the desired directory you want to move in.

cd [directory_name]

For Example: If we want to move to a subdirectory named "Documents"

cd Documents

1--CD-Documents

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

By using `/` as an argument in `cd` we can change the directory to the root directory. The root directory is the first directory in your file system hierarchy. 

cd /

2--CD-Slash

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

We 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: If we want to move to "dir name" = "My songs". We use the following command.

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

Syntax of the CD Command in Linux

The 'cd' command allows users to change their current working directory within the file system. The basic syntax of the `cd` command is as follows:

cd [directory]

Here, replace [directory] with the destination directory path you want to navigate to. If no directory is specified, 'cd' will redirect to your home directory by default. Let's explore the command's functionality through examples.

List of Navigating Command in Linux

In this table you will find all the navigating command in Linux. So go explore, the table and go through the whole article to know the examples.

Use CasesDescriptionExamples / Notes
Basic Syntaxcd [directory][directory]: Path to navigate to. Defaults to home if omitted.
Navigate to a Specific Directorycd /path/to/directorycd /var/log
Go Back to the Home Directorycd or cd ~cd or cd ~
Navigate to the Previous Directorycd -cd - from /var/log returns to /home/user/Documents
Navigate to the Parent Directorycd ..cd .. from /home/user/Documents moves to /home/user
Use Relative Pathscd subdirectorycd Documents moves from /home/user to /home/user/Documents
Use Absolute Pathscd /absolute/pathcd /usr/local/bin
Use Tab CompletionAuto-complete directory namescd /var/l + Tab => cd /var/log
Check Current DirectorypwdPrints the full path of your current location.
Handle Spaces in NamesUse quotes or escape spacescd "My Documents" or cd My\ Documents
Access Hidden DirectoriesInclude dot in pathcd .config
Directory Not FoundError: No such file or directoryEnsure correct path.
Insufficient PermissionsError: Permission deniedUse ls -l for permissions or sudo.
Navigate to Root Directorycd /Navigate to the root directory.
Chain Commandscd /path/to/directory && lsChanges directory and lists contents.
Add AliasesCreate shortcuts in shell config filealias docs="cd ~/Documents" and source ~/.bashrc

Explore