Linux cd Command
How cd works, the shortcuts worth memorising, why it is a shell builtin rather than a program, and how to jump back to where you were.
Formula
cd [DIRECTORY]
How to use it
- The synopsis at the top shows the general form of the command.
- Click any example to copy it straight to your clipboard.
- The options table lists only the flags worth remembering — run man for the exhaustive list.
Examples
| cd /var/log | jump to an absolute path |
| cd ../sibling | up one level, then into a sibling directory |
| cd - | toggle back to the previous directory |
Questions people ask
Why does cd not work inside a shell script the way I expect?
It does work, but only inside that script's own shell. Once the script exits, your interactive shell is unchanged. Source the script with `. script.sh` if you want the change to stick.
How do I get back to where I was?
cd - returns to the previous directory and prints it. Repeat it to toggle between two places.
Does this page work offline?
Yes, after the first visit. The whole reference is part of the page and the service worker caches it.
Runs entirely in your browser. Nothing you type is uploaded, logged or shared.
Last updated 22 August 2026