Changing the Directory in Linux | cd Command
Last Updated :
18 Oct, 2025
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.
Changing the Directory in LinuxPrerequisites:
- 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

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 /

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

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 ~

We can also pass the `cd` command with no arguments, which will eventually land us in our home directory.
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. 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"

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

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 Cases | Description | Examples / Notes |
|---|
| Basic Syntax | cd [directory] | [directory]: Path to navigate to. Defaults to home if omitted. |
| Navigate to a Specific Directory | cd /path/to/directory | cd /var/log |
| Go Back to the Home Directory | cd or cd ~ | cd or cd ~ |
| Navigate to the Previous Directory | cd - | cd - from /var/log returns to /home/user/Documents |
| Navigate to the Parent Directory | cd .. | cd .. from /home/user/Documents moves to /home/user |
| Use Relative Paths | cd subdirectory | cd Documents moves from /home/user to /home/user/Documents |
| Use Absolute Paths | cd /absolute/path | cd /usr/local/bin |
| Use Tab Completion | Auto-complete directory names | cd /var/l + Tab => cd /var/log |
| Check Current Directory | pwd | Prints the full path of your current location. |
| Handle Spaces in Names | Use quotes or escape spaces | cd "My Documents" or cd My\ Documents |
| Access Hidden Directories | Include dot in path | cd .config |
| Directory Not Found | Error: No such file or directory | Ensure correct path. |
| Insufficient Permissions | Error: Permission denied | Use ls -l for permissions or sudo. |
| Navigate to Root Directory | cd / | Navigate to the root directory. |
| Chain Commands | cd /path/to/directory && ls | Changes directory and lists contents. |
| Add Aliases | Create shortcuts in shell config file | alias docs="cd ~/Documents" and source ~/.bashrc |
Explore
Linux/Unix Tutorial
5 min read
Getting Started with Linux
Installation with Linux
Linux Commands
Linux File System
Linux Kernel
Linux Networking Tools
Linux Process
Linux Firewall
Shell Scripting & Bash Scripting