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

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.
| Symptom | What to check |
|---|---|
| No such file or directory | Check each path component, spelling, capitalization, and whether a space needs quoting. |
| Permission denied | You need search (execute) permission on the directory and its parent path components. |
| Not a directory | One path component is a regular file rather than a directory. |
| cd – has no previous path | Use 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.
