pwd
Overview
The pwd
(print working directory) command prints the name of the current working directory. It shows the full path from the root directory to your current location.
Syntax
pwd [options]
Common Options
Option | Description |
---|---|
-L |
Use PWD from environment (logical) |
-P |
Avoid symlinks (physical) |
--help |
Display help message |
--version |
Output version information |
Key Use Cases
- Show current location
- Verify directory path
- Use in scripts
- Check symbolic links
- Path confirmation
Examples with Explanations
Example 1: Basic Usage
pwd
Show current working directory
Example 2: Physical Path
pwd -P
Show physical path (resolve symlinks)
Example 3: Logical Path
pwd -L
Show logical path (with symlinks)
Understanding Output
- Absolute path from root (/)
- One line output
- No trailing slash
- Error messages for:
- Permission issues
- Read errors
- Path resolution problems
Common Usage Patterns
Script directory check:
current_dir=$(pwd)
Path verification:
pwd -P
Directory navigation:
cd $(pwd)
Performance Analysis
- Fast execution
- Minimal resource usage
- Built-in shell command
- Path resolution impact
- Symlink overhead