cd Cheatsheet
Basic Syntax
Core command forms for changing directories.
| Command | Description |
|---|---|
cd [DIRECTORY] |
Change to a directory |
cd |
Change to your home directory |
cd -- DIRECTORY |
Change to a directory whose name may start with - |
pwd |
Print the current working directory |
Everyday Navigation
Common ways to move around the filesystem.
| Command | Description |
|---|---|
cd /etc |
Change to an absolute path |
cd Downloads |
Change to a relative path |
cd .. |
Move up one directory |
cd ../.. |
Move up two directories |
cd ./scripts |
Change to a directory under the current directory |
Home Directories
Use shell shortcuts for your home directory and other users’ homes.
| Command | Description |
|---|---|
cd ~ |
Change to your home directory |
cd ~/Downloads |
Change to Downloads inside your home directory |
cd ~username |
Change to another user’s home directory |
cd "$HOME" |
Change to the directory stored in $HOME |
Relative Paths
Build paths from your current directory.
| Command | Description |
|---|---|
cd . |
Stay in the current directory |
cd .. |
Move to the parent directory |
cd ../src |
Move up one level, then into src |
cd ../../var |
Move up two levels, then into var |
cd project/docs |
Move through nested directories |
Previous Directory
Switch between recently used directories.
| Command | Description |
|---|---|
cd - |
Change to the previous working directory |
echo "$OLDPWD" |
Show the previous working directory |
cd "$OLDPWD" |
Change to the previous directory without using cd - |
pushd /path |
Change directory and save the old one on the stack |
popd |
Return to a directory from the stack |
Paths with Spaces
Quote or escape paths that contain spaces or shell metacharacters.
| Command | Description |
|---|---|
cd "Project Files" |
Quote a directory name with spaces |
cd 'Project Files' |
Use single quotes for a literal path |
cd Project Files |
Escape the space with a backslash |
cd -- "-reports" |
Enter a directory whose name starts with - |
Symlinks and Physical Paths
Control whether cd follows logical or physical paths.
| Command | Description |
|---|---|
cd -L linkdir |
Follow symbolic links (default in Bash) |
cd -P linkdir |
Resolve to the physical directory path |
pwd |
Show the shell’s logical current directory |
pwd -P |
Show the physical current directory |
cd -P .. |
Move using the physical directory structure |
CDPATH
Search extra base directories when changing by name.
| Command | Description |
|---|---|
export CDPATH=.:~/projects:/opt |
Search current directory, ~/projects, and /opt |
cd myapp |
Try matching myapp in each CDPATH entry |
unset CDPATH |
Disable CDPATH for the current shell |
CDPATH= cd myapp |
Run one cd command without CDPATH |
Troubleshooting
Quick checks for common directory-change errors.
| Issue | Check |
|---|---|
No such file or directory |
Verify the path with ls -ld path |
Permission denied |
Check execute permission on the directory |
| Path with spaces fails | Quote the path or escape spaces |
cd - fails |
$OLDPWD is not set yet |
Unexpected target with CDPATH |
Run unset CDPATH or use an absolute path |
| Symlink path looks different | Compare pwd and pwd -P |
Related Guides
Use these guides for detailed directory navigation workflows.
| Guide | Description |
|---|---|
cd Command in Linux: Change Directories
|
Full cd guide with examples |
How to Get the Current Working Directory in Linux
|
Use pwd and understand the current directory |
pushd and popd Commands in Linux
|
Work with the directory stack |
Linux Commands Cheatsheet
|
General Linux command quick reference |




