← All commands
THE COMMAND REFERENCE

cd

Change the current directory of your interactive shell.

Last updated

Portable / common

Implementation-level reference; examples are not certified for every installed version.

Overview

cd is a shell builtin because changing directory must affect the current shell. A separate executable cannot change its parent shell's directory. This reference documents Bash behavior; another shell can differ.

Background

cd is a shell builtin, not a separate program: the Bash manual lists it among the Bourne shell builtins. It has to be built in because the working directory belongs to the shell process, and a separate program could only change its own. Each shell supplies its own cd, so behaviour such as cd - and -P is a property of the shell, not of the operating system.

Examples

Move into a project directory:

cd projects

Move to the parent directory:

cd ..

Return to your home directory:

cd

Go to a directory under your home directory with the tilde shortcut:

cd ~/projects

Change directory and show where you ended up, stopping if the change fails:

cd projects && pwd

Common mistakes

Quote directory names containing spaces: cd 'project notes'. Chain with && rather than ; so later commands do not run in the wrong directory after a failed cd. A CDPATH variable can make cd name resolve somewhere unexpected. Your current directory changes how relative paths are interpreted. Confirm your location with pwd before running a command that modifies files.

Portability

A standalone explain binary cannot inspect your parent shell's aliases, functions, or exact builtin implementation. Zsh and dash builtins also exist and are not covered or tested here. Choose Bash explicitly when needed; a detected SHELL environment variable is not proof of the active shell.

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.