cd
Overview
The cd
(change directory) command is used to change the current working directory in Linux and Unix-like operating systems. It’s one of the most fundamental shell commands.
Syntax
cd [options] [directory]
Common Options
Option | Description |
---|---|
-L |
Follow symbolic links (default) |
-P |
Use physical directory structure |
-e |
Exit if error occurs |
--help |
Display help message |
- |
Change to previous directory |
~ |
Change to home directory |
.. |
Move up one directory |
. |
Current directory |
Key Use Cases
- Navigate directory structure
- Return to home directory
- Move between directories
- Access relative paths
- Follow symbolic links
Examples with Explanations
Example 2: Return Home
cd ~
# or simply
cd
Change to home directory
Example 3: Previous Directory
cd -
Return to previous directory
Understanding Output
- No output on success
- Error messages for:
- Permission denied
- No such directory
- Not a directory
- Path too long
Common Usage Patterns
Relative navigation:
cd ../directory
Absolute navigation:
cd /absolute/path
Home subdirectory:
cd ~/Documents
Performance Analysis
- Built-in shell command
- Instant execution
- No external process
- Memory efficient
- Path resolution impact