Navigating the File System

20 minLesson 2 of 16

Learning Objectives

  • Understand the Linux file system hierarchy
  • Navigate directories using cd, ls, and pwd
  • Work with absolute and relative paths
  • Use tab completion and shortcuts

The Linux File System

Everything in Linux is organized in a tree structure starting from the root directory /. Understanding this hierarchy is essential for DevOps work.

Key Directories

/
├── home/       # User home directories
├── etc/        # System configuration files
├── var/        # Variable data (logs, databases)
├── usr/        # User programs and utilities
├── tmp/        # Temporary files
├── opt/        # Optional/third-party software
├── bin/        # Essential command binaries
├── sbin/       # System administration binaries
└── dev/        # Device files

pwd — Print Working Directory

# Shows your current location
pwd
# Output: /home/username

ls — List Directory Contents

# Basic listing
ls
 
# Detailed listing with permissions
ls -l
 
# Show hidden files
ls -a
 
# Combine flags
ls -la
 
# Human-readable file sizes
ls -lh

cd — Change Directory

# Go to home directory
cd ~
cd
 
# Go to root
cd /
 
# Go up one level
cd ..
 
# Go to previous directory
cd -
 
# Navigate to a specific path
cd /var/log

Paths

Absolute Paths

Start from root /:

cd /home/username/documents
cd /etc/nginx/conf.d

Relative Paths

Start from current directory:

# If you're in /home/username
cd documents        # Goes to /home/username/documents
cd ../otheruser     # Goes to /home/otheruser
cd ./projects       # Goes to /home/username/projects

Useful Shortcuts

ShortcutDescription
~Home directory
.Current directory
..Parent directory
-Previous directory
TabAuto-complete
Tab TabShow all options

Practice Exercises

Try these commands in sequence:

# 1. Check where you are
pwd
 
# 2. Go to the root directory
cd /
 
# 3. List all top-level directories
ls -l
 
# 4. Navigate to /var/log
cd /var/log
 
# 5. List log files
ls -la
 
# 6. Go back home
cd ~
 
# 7. Create a practice directory
mkdir -p devops-practice/linux
 
# 8. Navigate into it
cd devops-practice/linux
 
# 9. Confirm your location
pwd

Summary

You now know how to:

  • Understand the Linux file system hierarchy
  • Navigate using cd, ls, and pwd
  • Work with absolute and relative paths
  • Use shortcuts for faster navigation

Next Steps

Next, we'll learn about file operations — creating, copying, moving, and deleting files and directories.