Skip to main content

cd Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for changing directories with cd in Linux

The `cd` command changes the current working directory in Linux shells. This cheatsheet covers everyday navigation, parent paths, home directory shortcuts, previous-directory jumps, symbolic link handling, and common errors.

Basic Syntax

Core command forms for changing directories.

CommandDescription
cd [DIRECTORY]Change to a directory
cdChange to your home directory
cd -- DIRECTORYChange to a directory whose name may start with -
pwdPrint the current working directory

Everyday Navigation

Common ways to move around the filesystem.

CommandDescription
cd /etcChange to an absolute path
cd DownloadsChange to a relative path
cd ..Move up one directory
cd ../..Move up two directories
cd ./scriptsChange to a directory under the current directory

Home Directories

Use shell shortcuts for your home directory and other users’ homes.

CommandDescription
cd ~Change to your home directory
cd ~/DownloadsChange to Downloads inside your home directory
cd ~usernameChange to another user’s home directory
cd "$HOME"Change to the directory stored in $HOME

Relative Paths

Build paths from your current directory.

CommandDescription
cd .Stay in the current directory
cd ..Move to the parent directory
cd ../srcMove up one level, then into src
cd ../../varMove up two levels, then into var
cd project/docsMove through nested directories

Previous Directory

Switch between recently used directories.

CommandDescription
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 /pathChange directory and save the old one on the stack
popdReturn to a directory from the stack

Paths with Spaces

Quote or escape paths that contain spaces or shell metacharacters.

CommandDescription
cd "Project Files"Quote a directory name with spaces
cd 'Project Files'Use single quotes for a literal path
cd Project\ FilesEscape the space with a backslash
cd -- "-reports"Enter a directory whose name starts with -

Control whether cd follows logical or physical paths.

CommandDescription
cd -L linkdirFollow symbolic links (default in Bash)
cd -P linkdirResolve to the physical directory path
pwdShow the shell’s logical current directory
pwd -PShow the physical current directory
cd -P ..Move using the physical directory structure

CDPATH

Search extra base directories when changing by name.

CommandDescription
export CDPATH=.:~/projects:/optSearch current directory, ~/projects, and /opt
cd myappTry matching myapp in each CDPATH entry
unset CDPATHDisable CDPATH for the current shell
CDPATH= cd myappRun one cd command without CDPATH

Troubleshooting

Quick checks for common directory-change errors.

IssueCheck
No such file or directoryVerify the path with ls -ld path
Permission deniedCheck execute permission on the directory
Path with spaces failsQuote the path or escape spaces
cd - fails$OLDPWD is not set yet
Unexpected target with CDPATHRun unset CDPATH or use an absolute path
Symlink path looks differentCompare pwd and pwd -P

Use these guides for detailed directory navigation workflows.

GuideDescription
cd Command in Linux: Change DirectoriesFull cd guide with examples
How to Get the Current Working Directory in LinuxUse pwd and understand the current directory
pushd and popd Commands in LinuxWork with the directory stack
Linux Commands CheatsheetGeneral Linux command quick reference