Beginner โฑ 15 min Lesson 2 of 13

๐Ÿ“‚ Navigating the File System

Master pwd, ls, cd, and learn absolute vs relative paths.

Finding Your Way Around

The Linux file system is a tree structure that starts at the root directory /. Every file and folder on your system lives somewhere inside this tree. Learning to navigate it efficiently is the first real skill every Bash user needs.

Where Am I? โ€” pwd

pwd stands for Print Working Directory. It shows the full path to your current location in the file system.

bash
pwd
# Output example: /home/username

What's Here? โ€” ls

The ls command lists the contents of a directory. Without arguments it shows the current directory.

bash
# Basic listing
ls

# Long format with details (permissions, size, date)
ls -l

# Show hidden files (files starting with a dot)
ls -a

# Combine flags โ€” long format + hidden + human-readable sizes
ls -lah

# List a specific directory
ls /etc
๐Ÿ’ก Tip: Hidden files in Linux start with a dot (.), like .bashrc. They won't appear with plain ls; use ls -a.

Moving Around โ€” cd

cd stands for Change Directory. It moves you to a different location in the file system.

bash
# Go to your home directory
cd ~
cd          # same thing โ€” cd with no argument goes home

# Go to root
cd /

# Go up one level
cd ..

# Go up two levels
cd ../..

# Go to the previous directory
cd -

# Go to an absolute path
cd /var/log

Absolute vs Relative Paths

Understanding the difference is critical:

  • Absolute path: Starts from root (/). Always works regardless of your current location. Example: /home/user/Documents
  • Relative path: Starts from your current directory. Example: Documents/notes.txt or ../Downloads

Creating & Removing Directories

bash
# Create a directory
mkdir projects

# Create nested directories in one command
mkdir -p projects/bash/scripts

# Create an empty file
touch myfile.txt

# Remove an empty directory
rmdir projects

# Remove a directory with contents (be careful!)
rm -r projects
โš ๏ธ Warning: rm -r deletes a directory and all its contents permanently. There is no trash can. Double-check before running it!

Try It Yourself

Practice navigating and creating directories in the interactive terminal below.

Terminal

Summary

You now know how to check your location with pwd, list files with ls, move around with cd, and create directories with mkdir. These are commands you'll use every single day.

๐Ÿงช Test Your Knowledge

Answer the questions below to check your understanding of this lesson.