What is cd command in linuxThe cd command in Linux is very helpful when navigating through the file system of a Linux operating system. This command is one of the most common used commands in the Linux Terminal.
It allows you to change from one directory location to another.
In this article, we will talk about what the cd command is, how it works, how to use it (syntax) and give you visual examples of how to use the cd command.
We will cover the mistakes that new Linux users often make with the cd command, provide an example of the professional way to use it
We will provide a command reference sheet, and answer 20 frequently asked questions (FAQs) about the cd command to give you maximum clarity regarding the cd command in Linux.
π Table of Contents
- What Is cd Command in Linux?
- Why Is cd Command Important?
- Linux Directory Structure
- Syntax of cd Command
- Check Current Directory
- Examples of cd Command
- Absolute vs Relative Path
- Folders with Spaces
- Common Errors
- cd Command in Kali Linux
- Best Practices
- cd vs ls vs pwd
- Frequently Asked Questions (20)
- cd Command Cheat Sheet
What Is cd Command in Linux?
The cd command in Linux stands for Change Directory.
You can use the cd command when using the terminal in a Linux operating system to move from one directory (or folder) to another in your computer’s file system.
This command allows you to tell Linux where to navigate within the file system.
Why Is cd Command Important in Linux?
Linux heavily depends on the command line. Without this command, navigation becomes difficult.
- Access files and folders
- Run programs and scripts
- Install software
- System administration
- Cybersecurity and ethical hacking
Understanding Linux Directory Structure
The Linux file system uses a hierarchy (tree structure) where the root directory (/) is the top of the tree and the starting point for every other file and folder.
You should understand how the Linux file system is structured before you start running commands such as the cd command.
In the following list, we will explain each of the important Linux directories in just one simple line, allowing beginner users to quickly grasp the concept behind the directory.
Root Level Directories in Linux
-
/β The root of the Linux file system and the starting point for all directories. -
/binβ Contains essential commands available to all users, such asls,cd, andcp. -
/bootβ Stores bootloader files required to load the Linux kernel during system startup. -
/devβ Contains device files that represent hardware devices like disks, USB drives, and keyboards. -
/etcβ Holds system-wide configuration files and settings for the entire machine. -
/homeβ Contains personal directories for each user; users log in directly to their home directory. -
/libβ Stores essential shared libraries required for running system programs. -
/lib64β Contains shared libraries required to run 64-bit applications. -
/mediaβ Used as a mount point for removable media like USB drives, DVDs, and CDs. -
/mntβ Temporary mount point for file systems that are not permanently mounted. -
/optβ Stores optional or third-party software installed by users or vendors. -
/procβ A virtual file system that provides real-time information about running processes and system hardware. -
/rootβ The home directory of the root (administrator) user. -
/runβ Contains runtime data such as process IDs and system state information. -
/sbinβ Stores system administration commands mainly used by the root user. -
/srvβ Contains data used by services like web servers, FTP servers, and other network services. -
/sysβ A virtual directory that exposes information about devices, drivers, and kernel subsystems. -
/tmpβ Stores temporary files that are usually deleted when the system reboots. -
/usrβ Contains user applications, libraries, documentation, and system utilities. -
/varβ Stores variable data such as logs, cache files, mail, and databases that change frequently.
Beginner Tip: Understanding these root directories makes it much easier to use the cd command in Linux safely and confidently.
Important Subdirectories Explained
/home Directory
- /home/username β Personal workspace of a user.
- /home/username/Documents β Stores documents and files.
- /home/username/Downloads β Default location for downloaded files.
- /home/username/Desktop β Files visible on the desktop.
/usr Directory
- /usr/bin β Most user commands and programs.
- /usr/sbin β System administration tools.
- /usr/lib β Libraries for programs in /usr/bin.
- /usr/share β Architecture-independent data like documentation and icons.
/var Directory
- /var/log β System and application log files.
- /var/cache β Cached data from applications.
- /var/tmp β Temporary files kept longer than /tmp.
/proc and /sys (Virtual Directories)
- /proc β Provides information about running processes and kernel.
- /sys β Shows hardware and kernel-related information.
Why Understanding Linux Directory Structure Is Important
- Helps you use the cd command in Linux correctly
- Prevents accidental deletion of system files
- Makes system administration easier
- Essential for cybersecurity and ethical hacking
- Improves confidence while working in terminal
Beginner Tip: Always explore directories using ls and confirm your location with pwd before performing important operations.
Once you understand the Linux file and folder structure, using the cd command becomes simple, safe, and powerful.
Syntax of cd Command in Linux
cd directory_name
Example:
cd Documents
Check Current Directory Using pwd
pwd
This command shows your current working directory.
Common Examples of cd Command
cd Downloads
cd ..
cd /
cd ~
cd -
Understanding the cd command in Linux becomes very easy when you practice it with real examples. Below are the most commonly used examples of the cd command, explained in simple language for beginners.
1. Move into a Directory
This command moves you into a folder that exists inside your current directory.
cd Downloads
If your current directory is /home/user, this command will take you to:
/home/user/Downloads
2. Move One Directory Up (Parent Directory)
The double dot (..) represents the parent directory. This command is used when you want to go back one level.
cd ..
Example:
/home/user/Documents β /home/user
This is one of the most frequently used cd commands in Linux.
3. Go to the Root Directory
The root directory (/) is the top-most directory in Linux. All files and folders start from here.
cd /
After running this command, your location becomes:
/
This command is commonly used by system administrators.
4. Go to the Home Directory
You can move directly to your home directory using either of the following commands:
cd
cd ~
Both commands take you to:
/home/username
This is very useful when you feel lost in the directory structure.
5. Go to the Previous Directory
The hyphen (-) tells Linux to return to the directory you were in before the current one.
cd -
This command is extremely helpful when switching back and forth between two directories.
Tip for Beginners: Always use the pwd command after using cd to confirm your current directory.
Absolute Path vs Relative Path
One of the most important concepts to understand while learning the cd command in Linux is the difference between an absolute path and a relative path. Many beginners face errors because they do not understand this difference clearly.
Absolute Path
An absolute path is a complete path that starts from the root directory (/). It shows the exact location of a directory, no matter where you are currently in the file system.
cd /home/user/Documents
Explanation:
/β Root directoryhomeβ Home directory locationuserβ UsernameDocumentsβ Target folder
Even if your current directory is /var/log or /usr/bin, this command will always take you to:
/home/user/Documents
When to use absolute path:
- While writing scripts
- For system administration tasks
- When accuracy is critical
- To avoid navigation mistakes
Relative Path
A relative path depends on your current working directory. It does not start from the root directory and works only if the target folder exists relative to where you are.
cd Documents
Example:
If your current directory is:
/home/user
Then the above command will take you to:
/home/user/Documents
However, if your current directory is:
/var/log
The same command will result in an error:
bash: cd: Documents: No such file or directory
When to use relative path:
- For quick navigation
- When you are sure about your current directory
- During daily terminal usage
Key Differences Between Absolute and Relative Path
| Absolute Path | Relative Path |
|---|---|
| Starts from root (/) | Starts from current directory |
| Works from any location | Depends on current directory |
| More reliable and safe | Faster but riskier |
| Used in scripts and admin work | Used for quick navigation |
Beginner Tip: If you are unsure about your current directory, always use an absolute path with the cd command to avoid errors.
Using cd with Folder Names Having Spaces
Using cd Command with Folder Names That Contain Spaces
When using the cd command in Linux, beginners often face errors if a folder name contains spaces. Linux treats spaces as separators, so you must handle them correctly while navigating directories.
Method 1: Using Double Quotes (Recommended)
Enclose the folder name in double quotes. This is the easiest and most readable method.
cd "My Folder"
cd "Project Files"
Method 2: Using Backslash (Escape Character)
You can escape spaces using a backslash (\) before each space.
cd My\ Folder
cd Project\ Files
Method 3: Using Tab Auto-Completion (Best Practice)
Start typing the folder name and press the Tab key. Linux will auto-complete the name and handle spaces automatically.
cd Pro<Tab>
Common Mistake
β Incorrect:
cd My Folder
β Correct:
cd "My Folder"
Beginner Tip: Prefer double quotes or tab completion, and avoid spaces in folder names when possible.
Common Errors While Using cd Command
- No such file or directory
- Permission denied
- Case sensitivity mistakes
Best Practices While Using cd Command
Using the cd command in Linux looks simple, but following best practices helps you avoid mistakes, improve speed, and work safelyβespecially as a beginner. Below are 20 important best practices every Linux user should follow while using the cd command.
- Always check your current directory using
pwdbefore changing directories. - Use
lsto list files and folders before running the cd command. - Prefer using absolute paths when accuracy is important.
- Use
cd ~orcdto quickly return to your home directory. - Use
cd ..carefully to avoid moving to the wrong parent directory. - Combine
cdwithlsto confirm directory contents after navigation. - Use quotes or backslashes when directory names contain spaces.
- Avoid running delete or move commands immediately after cd without verification.
- Use
cd -to switch quickly between two directories. - Be careful with case sensitivityβLinux treats uppercase and lowercase differently.
- Do not try to cd into directories without proper permissions.
- Use tab completion to reduce typing errors and speed up navigation.
- Confirm directory existence before using cd in scripts.
- Use absolute paths in shell scripts to avoid unexpected behavior.
- Avoid working inside system directories unless you understand their purpose.
- Use
pwdfrequently when working deep inside directory structures. - Practice navigating using relative paths to improve Linux command confidence.
- Do not assume directory structure is the same on every Linux system.
- In Kali Linux, always confirm your location before running hacking tools.
- Build a habit of slow and careful navigation when working as root user.
Beginner Tip: Safe navigation using the cd command in Linux prevents accidental file deletion and makes you a confident Linux user.
Master Linux cd command options for terminal navigation.
| Command | Description | Example |
|---|---|---|
cd [directory] |
Change to specific directory | cd /home/user/docs |
cd .. |
Move up one directory | cd .. |
cd ../.. |
Move up two directories | cd ../../ |
cd ~ |
Go to home directory | cd ~ |
cd |
Go to home (no argument) | cd |
cd - |
Return to previous directory | cd - |
cd / |
Go to root directory | cd / |
cd ~/dir |
Absolute path from home | cd ~/Downloads |
cd "dir with spaces" |
Directory with spaces | cd "My Folder" |
πΎ Quick reference for Kali Linux & cybersecurity workflows.
Difference Between cd, ls, and pwd
| Command | Purpose |
|---|---|
| cd | Change directory |
| ls | List files |
| pwd | Show current directory |
Frequently Asked Questions (FAQ)
-
What is cd command in Linux?
The cd command in Linux is used to change the current working directory in the Linux terminal. -
What does cd stand for?
cd stands for Change Directory and is used for directory navigation in Linux. -
Is the cd command case sensitive?
Yes, Linux is case sensitive, so directory names must match exactly when using the cd command. -
What happens if I type cd without any argument?
Typing cd alone takes you directly to your home directory. -
How do I go back one directory in Linux?
You can move to the parent directory using the commandcd ... -
How to go to the root directory using cd command?
Usecd /to move to the root of the Linux file system. -
What is cd ~ command?
The cd ~ command is used to navigate to the userβs home directory. -
What does cd – do?
The cd – command switches you back to the previous working directory. -
What is an absolute path in Linux?
An absolute path starts from the root directory and shows the complete location of a folder. -
What is a relative path in Linux?
A relative path is based on the current directory and does not start from the root. -
Can the cd command be used in shell scripts?
Yes, the cd command is commonly used in bash and shell scripts for directory navigation. -
Why does the cd command show an error?
Errors occur due to incorrect paths, missing directories, or permission issues. -
How to use cd command with folder names having spaces?
Use quotes or backslashes to handle spaces in directory names. -
Does the cd command work the same in Kali Linux?
Yes, the cd command in Kali Linux works exactly like other Linux distributions. -
Can the cd command delete files or folders?
No, the cd command is only used for navigation and cannot delete anything. -
Is cd a built-in Linux command?
Yes, cd is a shell built-in command, not an external binary. -
Which command shows the current working directory?
Thepwdcommand displays the present working directory in Linux. -
Which command lists files and directories?
Thelscommand is used to list files and folders in a directory. -
Is cd command important for ethical hacking?
Yes, ethical hackers use the cd command frequently to navigate tool and log directories. -
Can cd fail even if the directory exists?
Yes, cd can fail if you do not have permission to access the directory.
cd Command in Linux β Quick Cheat Sheet
| Command | Description |
|---|---|
| cd folder | Enter folder |
| cd | Home directory |
| cd / | Root directory |
| cd .. | One level up |
| cd – | Previous directory |
| pwd | Show location |
| ls | List files |
Final Thoughts
The cd command in Linux is simple but extremely powerful. Mastering it will make Linux navigation easy, safe, and efficient.
If you want to learn Linux, cybersecurity,ethical hacking, understanding the cd command is essential.
π Basic Linux Commands – Master Terminal in 5 Minutes!







