Navigating the Linux Shell

Overview

The shell is your command-line interface to Linux. Learning to navigate the filesystem efficiently is the foundation of Linux mastery. Every file and directory has a path, and understanding how to move between them is essential.

Key Commands

Print Working Directory

pwd

Displays your current location in the filesystem. This shows the absolute path of where you are.

Example:
pwd
Output: /home/username - You are in the username home directory

List Directory Contents

ls

Lists files and directories in your current location.

Options:

  • -l - Long format showing permissions, owner, size, and date
  • -a - Shows all files including hidden ones (starting with .)
  • -h - Human-readable file sizes (KB, MB, GB)
  • -R - Recursively list subdirectories
Example:
ls -lah
Lists all files in long format with human-readable sizes

Change Directory

cd directory_name

Moves you to a different directory. This is how you navigate the filesystem.

Special Paths:

  • cd ~ - Go to your home directory
  • cd .. - Go up one directory level
  • cd - - Go to previous directory
  • cd / - Go to root directory
  • cd ../../ - Go up two directory levels
Example:
cd Documents
Moves into the Documents folder from your current location

Create Directory

mkdir directory_name

Creates a new directory (folder) in your current location.

Options:

  • -p - Creates parent directories if they don't exist
Example:
mkdir -p projects/web/css
Creates the entire directory structure at once

Remove Directory

rmdir directory_name

Removes an empty directory. Use with caution!

Alternative:

  • rm -r directory_name - Removes directory and all contents (dangerous!)

Path Types

Absolute Path

Starts from the root directory (/) and specifies the complete path.

Example:
/home/username/Documents/report.txt
Full path from root to the file

Relative Path

Starts from your current location, doesn't begin with /

Example:
Documents/report.txt
Path relative to where you currently are

Important Notes

  • Case sensitive: Linux treats Documents and documents as different directories
  • Tab completion: Press Tab to auto-complete directory and file names
  • Spaces in names: Use quotes or backslashes: cd "My Documents" or cd My\ Documents
  • Hidden files: Files starting with . are hidden, use ls -a to see them

Practice Levels