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

  1. Show current location
  2. Verify directory path
  3. Use in scripts
  4. Check symbolic links
  5. 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

  1. Script directory check:

    current_dir=$(pwd)
  2. Path verification:

    pwd -P
  3. Directory navigation:

    cd $(pwd)

Performance Analysis

  • Fast execution
  • Minimal resource usage
  • Built-in shell command
  • Path resolution impact
  • Symlink overhead

Additional Resources