cd Command in Linux: Change Directories

cd Command in Linux: Change Directories

Moving between folders in a terminal starts with knowing which directory the shell is working in. The cd command changes the shell’s current directory to a path or a destination such as your home directory.

This article explains how to choose a path to a directory and use cd’s shortcuts to move from there.

TL;DR

The cd command changes the current directory in your shell, using a path you provide or a shortcut such as ~, .., or -.

  • Use cd path/to/directory for a relative path and cd /path/to/directory for an absolute path.
  • Use cd or cd ~ for your home directory, cd .. for its parent, and cd – for the previous directory.
  • Quote a directory name that contains spaces, such as cd “My Notes”.

What Does the cd Command Do in Linux?

cd is a shell builtin that changes the working directory of the shell where you type it. Relative paths are resolved from that location, while paths beginning with / start at the filesystem root.

A child process cannot change its parent shell’s directory. As a result, cd in a script affects commands in that script but leaves the terminal that launched it where it was.

Check your location with the pwd command. It prints the current path.

pwd

How to Use the cd Command in Linux

The following steps cover path navigation, the common shortcuts, and directory names that contain spaces.

Step 1: Move with a relative or absolute path

For example, cd projects uses a relative path while cd /home/username/projects uses an absolute path. The first expects projects below your current location. Replace the example absolute path with a directory that exists on your system.

cd projects
cd /home/username/projects

Run pwd after cd to check where you landed. A successful directory change is usually silent.

Step 2: Go home, to the parent, or back

With no argument or with ~, cd goes to HOME. Use .. for the parent directory and – for the directory stored in OLDPWD.

cd
cd ~
cd ..
cd -

Unlike the other forms, cd – prints the destination as it switches. Use cd once to set OLDPWD before trying cd -.

Step 3: Enter a directory whose name has spaces

Put quotes around the full path so the shell passes it to cd as one argument. Backslash-escaping each space works too.

cd "My Notes"
cd My\ Notes

I ran the named shell script below. It made a local demo directory, moved through it, and printed each destination. The command and output are shown here exactly as captured.

bash cd_navigation_demo.sh
Starting directory: /home/ubuntu/.cache/journaldev-article-runs/linuxfordevices-cd-command-in-linux-20261017T194832Z-0f7f900f7467/cd-demo
Relative path: /home/ubuntu/.cache/journaldev-article-runs/linuxfordevices-cd-command-in-linux-20261017T194832Z-0f7f900f7467/cd-demo/projects
Path with spaces: /home/ubuntu/.cache/journaldev-article-runs/linuxfordevices-cd-command-in-linux-20261017T194832Z-0f7f900f7467/cd-demo/projects/My Notes
/home/ubuntu/.cache/journaldev-article-runs/linuxfordevices-cd-command-in-linux-20261017T194832Z-0f7f900f7467/cd-demo
Previous directory: /home/ubuntu/.cache/journaldev-article-runs/linuxfordevices-cd-command-in-linux-20261017T194832Z-0f7f900f7467/cd-demo
Parent directory: /home/ubuntu/.cache/journaldev-article-runs/linuxfordevices-cd-command-in-linux-20261017T194832Z-0f7f900f7467
Terminal output showing cd navigation through relative, spaced, previous, and parent directories

The output confirms that a relative cd moves into the child directory and that the spaced path is one destination. The final lines show that cd – returns to the previous location while cd .. selects the parent.

cd Command Errors and Shell Behavior

When cd fails, the shell stays in its previous directory. Check the path spelling and permissions before running later commands that depend on the destination.

SymptomWhat to check
No such file or directoryCheck each path component, spelling, capitalization, and whether a space needs quoting.
Permission deniedYou need search (execute) permission on the directory and its parent path components.
Not a directoryOne path component is a regular file rather than a directory.
cd – has no previous pathUse cd once to set OLDPWD before trying cd -.

Use a failure check before commands that depend on a specific directory. For example, cd /path/to/project || exit 1 stops the script if navigation fails.

Bash follows symbolic links by default and keeps the logical path. With cd -P, it resolves the physical path instead. CDPATH can make Bash search configured base directories for a relative name.

If cd lands somewhere unexpected, inspect CDPATH or use an absolute path. These behaviors are Bash-specific, so check your shell’s manual if you use another shell.

For a related next step, see the LinuxForDevices guide to absolute and relative paths in Linux.

Conclusion: Choose the Path from Your Current Directory

Use cd to change the shell location, then run pwd before commands that depend on that directory.

For exact Bash behavior, consult the GNU Bash manual entry for cd and the Bash tilde-expansion documentation.

FAQ

These answers cover two common questions about what cd means and where its behavior comes from.

What does cd mean in Linux?

cd means change directory. It is a shell builtin that changes the shell’s current working directory.

Where is the cd command located in Linux?

In Bash, cd is a shell builtin, not a separate executable file. Bash handles it directly so it can change the current shell’s directory.

What is the difference between cd .. and cd -?

cd .. moves to the parent directory. cd – switches to the previous working directory stored in OLDPWD.