Back to Blog

Zsh Tutorial: Navigate Files Like a Pro | cd, pwd, ls Commands (Lesson 2)

Sandy LaneSandy Lane

Video: Zsh Tutorial: Navigate Files Like a Pro | cd, pwd, ls Commands (Lesson 2) by Taught by Celeste AI - AI Coding Coach

Watch full page →

Zsh Tutorial: Navigate Files Like a Pro | cd, pwd, ls Commands (Lesson 2)

Mastering navigation in the macOS file system using Zsh is essential for efficient command-line work. This lesson covers how to determine your current directory, move between folders, list directory contents with details, and use handy path shortcuts and tab completion to speed up navigation.

Code

# Show your current directory (Print Working Directory)
pwd

# Change directory to Documents folder inside your home directory
cd ~/Documents

# Move up one directory level (to parent directory)
cd ..

# Go to the previous directory you were in
cd -

# Return to your home directory
cd ~

# List files and folders in the current directory
ls

# List files with detailed info (permissions, size, date)
ls -l

# Show all files including hidden ones (those starting with .)
ls -a

# Combine options: detailed listing with hidden files and human-readable sizes
ls -lah

# Use tab completion to auto-complete directory or file names
# Example: type 'cd Doc' then press Tab to complete 'Documents'

Key Points

  • pwd displays the full path of your current working directory, helping you know exactly where you are.
  • cd changes your directory; use shortcuts like ~ for home, .. for parent, and - for previous directory.
  • ls lists directory contents; options like -l, -a, and -h provide detailed, hidden, and human-readable info.
  • Path shortcuts (~, ., .., -, /) save time and simplify navigation commands.
  • Tab completion helps auto-complete file and folder names, reducing typing and errors, and can be triggered by pressing Tab once or twice.