cd Change the current directory
Moves your shell into another folder, so that later commands work from there. It is part of the shell itself, not a separate program. With no argument it takes you to your home folder.
Synopsis
cd [-L | -P] [DIRECTORY]
cd -
Common options
| Option or form | What it does |
|---|---|
(no argument) | Go to your home folder, the one named by $HOME |
- | Go back to the previous directory and print its path. The shell remembers it in $OLDPWD |
.. | Go up one level, to the parent folder. Chain them as ../.. to go up two |
~ | Shorthand for your home folder, expanded by the shell. ~/Documents means a folder inside home |
-L | Follow symbolic links logically, so the path you see keeps the link name. This is the default |
-P | Use the physical path instead, with every symbolic link resolved to the real folder |
Examples
cd docs && pwd
cd docs/old && cd .. && pwd
cd && pwd
cd docs && cd -
mkdir -p build/out && cd build/out && pwd
cd -P /var/log
Notes
- cd is a shell builtin, not a program on disk, which is why it can change the folder of your current shell. A script that runs cd only changes its own directory, and your terminal stays where it was.
- Folder names with spaces need quotes, for example cd "My Documents", or a backslash before each space.
- In a script, check that cd worked before carrying on, for example cd build || exit 1. If cd fails and the script continues, later commands such as rm run in the wrong place.
- cd - swaps between your current and previous folder, so running it twice returns you to where you started.
- If a command in a pipeline or a ( ) subshell runs cd, the change ends when that subshell ends. Use cd on its own line, or wrap commands in braces, to change the main shell.
See also
Last reviewed 2026-10-07.