The cd command — short for change directory — is the most fundamental navigation command in Linux. Every Linux user, from beginners to senior sysadmins, uses it dozens of times per session. This guide covers every variant of cd you will need in real-world Linux work.
Basic Usage — cd to a Directory
$ cd /path/to/directory
After running cd, verify your current location with pwd (print working directory):
$ pwd
cd with Absolute Paths
An absolute path starts from the filesystem root / and specifies the complete path to the destination:
$ cd /var/log/nginx
$ cd /home/irfan/projects
$ cd /etc/nginx/sites-available
Absolute paths work from any directory — they always lead to the same place regardless of where you currently are.
cd with Relative Paths
A relative path is relative to your current directory. If you are in /home/irfan and want to go to /home/irfan/projects/myapp:
$ cd projects/myapp
No leading / means the path starts from your current location.
Go to Your Home Directory
Three equivalent ways to return to your home directory (/home/username):
$ cd
$ cd ~
$ cd $HOME
All three do the same thing. cd with no arguments is the fastest to type.
Go Up One Directory — cd ..
Two dots (..) represents the parent directory:
$ cd .. # Up one level
$ cd ../.. # Up two levels
$ cd ../../etc # Up two levels, then into etc/
Go to the Previous Directory — cd –
The hyphen shortcut is one of the most useful cd tricks:
$ cd /var/log
$ cd /etc/nginx
$ cd - # Returns to /var/log
cd - toggles between your current and previous directory. It is invaluable when you need to move back and forth between two locations repeatedly — a log directory and a config directory, for example.
Navigate with Tab Completion
Start typing a directory name and press Tab to autocomplete:
$ cd /var/lo[Tab] # Completes to /var/log/
$ cd /etc/ngi[Tab] # Completes to /etc/nginx/
If multiple directories match, press Tab twice to see all options.
Directories with Spaces — Quoting
If a directory name contains spaces, wrap it in quotes:
$ cd "My Documents"
$ cd 'My Documents'
$ cd My\ Documents # Backslash escaping also works
Leave a Reply