cd
What is cd?
cd: Change Directory — Navigate to a different directory. cd changes the current folder in a terminal. cd projects/shop moves into that folder, cd .. goes up one level, cd ~ or just cd goes to your home folder, and cd - jumps back to the previous one. Every command you run uses the current folder as its starting point. Relative paths, Git commands and project scripts all depend on where you are.
Frequently asked questions about cd
What should you keep in mind with cd?
In scripts, be careful with cd. If it fails because a folder does not exist, the script carries on in the wrong place, and the next command, such as a delete, runs where you did not intend. Use cd /path || exit 1, or set -e at the top, so the script stops when cd fails. Better still, use absolute paths for anything destructive.
At a glance
| Category | CLI commands |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |