cd

Learn how to use the

Change Directory (cd) Command Guide

Understanding the cd Command

The cd command, short for "change directory," is a fundamental command-line utility in Unix-like operating systems (Linux, macOS) and also available in Windows Command Prompt and PowerShell. It allows users to navigate through the file system by changing the current working directory.

Basic cd Command Usage

Here are the most common ways to use the cd command:

# Go to a specific directory by providing its path:
cd path/to/directory

# Go to your home directory (usually represented by '~'):
cd

# Go up one level to the parent directory of the current directory:
cd ..

# Go back to the previous directory you were in:
cd -

Advanced cd Command Options

For more specific navigation needs, cd offers additional options:

# Go to a physical directory, ignoring symbolic links:
cd -P path/to/dir

# Note: Some users alias 'cd' to 'cd -P' and 'pwd' to 'pwd -P'
# to ensure consistent behavior with symbolic links. This means that
# commands like `ls ..` and `cd ..; ls .` will yield the same results,
# regardless of whether the parent directory is a symbolic link.

Best Practices and Tips

  • Use tab completion to auto-fill directory names and reduce typing errors.
  • Be mindful of case sensitivity in directory names on Linux/macOS.
  • Use pwd (print working directory) to confirm your current location.
  • Combine cd with other commands for powerful scripting.

External Resources