What Is cd Command in Linux | cd Command:1 Powerful Guide

what is cd command in linux

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?

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 as ls, cd, and cp.
  • /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 directory
  • home → Home directory location
  • user → Username
  • Documents → 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 pwd before changing directories.
  • Use ls to list files and folders before running the cd command.
  • Prefer using absolute paths when accuracy is important.
  • Use cd ~ or cd to quickly return to your home directory.
  • Use cd .. carefully to avoid moving to the wrong parent directory.
  • Combine cd with ls to 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 pwd frequently 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 command cd ...
  • How to go to the root directory using cd command?
    Use cd / 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?
    The pwd command displays the present working directory in Linux.
  • Which command lists files and directories?
    The ls command 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.


Coding Journey


Coding Journey on Sulekha


  • 🚀 Basic Linux Commands – Master Terminal in 5 Minutes!
  • Leave a Comment

    Your email address will not be published. Required fields are marked *