cd Command
The cd command (change directory) is used to navigate between directories in the Linux file system. It's one of the most essential commands for terminal navigation.
Syntax
cd [directory]
Description
The cd command changes the current working directory to the specified directory. If no directory is specified, it changes to the user's home directory.
Key concepts:
- Absolute path: Full path from root directory (starts with /)
- Relative path: Path relative to current directory
- Home directory: User's personal directory (~)
- Parent directory: One level up (..)
- Current directory: Current location (.)
Examples
Go to home directory
cd
cd ~
cd $HOME
cd ~
cd $HOME
All three commands navigate to your home directory
Change to specific directory
cd /usr/local/bin
Changes to the /usr/local/bin directory (absolute path)
Navigate using relative paths
cd Documents
cd ../Downloads
cd ../../
cd ../Downloads
cd ../../
Navigate to Documents, then to Downloads, then up two levels
Go to parent directory
cd ..
Moves up one directory level
Go to previous directory
cd -
Returns to the previous directory you were in
Navigate to root directory
cd /
Changes to the root directory of the file system
Handle spaces in directory names
cd "My Documents"
cd My\ Documents
cd My\ Documents
Use quotes or escape spaces in directory names
Common Directory Shortcuts
| Shortcut | Description |
|---|---|
~ |
Home directory |
. |
Current directory |
.. |
Parent directory |
- |
Previous directory |
/ |
Root directory |
Tips
- Use
pwdto see your current directory - Use
lsto see available directories - Tab completion can help with long directory names
- Use
cd -to quickly switch between two directories - The
CDPATHenvironment variable can set search paths for cd