Lesson 1: Navigation Basics

Goal: Learn to move around the Linux filesystem with confidence.


Table of Contents

  1. Where Am I? — pwd
  2. List Files — ls
  3. Change Directory — cd
  4. Directory Structure — tree
  5. Absolute vs Relative Paths
  6. Exercises

Where Am I? — pwd

pwd stands for Print Working Directory. It tells you exactly where you are in the filesystem.

pwd

Example output:

/home/benjamin

You are currently in the home directory of the user benjamin. Every user has their own home directory under /home/.

Why is this important?

When you open a terminal, you always start in a specific directory. Before running any command, it's a good idea to know where you are — especially before deleting or moving files.


List Files — ls

ls lists the contents of the current directory.

Basic usage

ls

Example output:

Desktop  Documents  Downloads  Music  Pictures  Videos

Show hidden files

Files starting with a dot (.) are hidden in Linux. To see them:

ls -a

Example output:

.  ..  .bashrc  .config  .profile  Desktop  Documents  Downloads
  • . = current directory
  • .. = parent directory
  • .bashrc, .config, .profile = hidden configuration files

Detailed list view

ls -l

Example output:

drwxr-xr-x 2 benjamin benjamin 4096 Mar 15 10:30 Desktop
drwxr-xr-x 3 benjamin benjamin 4096 Mar 14 09:15 Documents
-rw-r--r-- 1 benjamin benjamin  220 Mar 10 08:00 .bashrc

Each column means:

drwxr-xr-x  2  benjamin  benjamin  4096  Mar 15 10:30  Desktop
│           │  │         │         │     │              └── Name
│           │  │         │         │     └── Last modified
│           │  │         │         └── Size in bytes
│           │  │         └── Group
│           │  └── Owner
│           └── Number of links
└── Permissions (d = directory, - = file)

Combine flags

You can combine multiple flags:

# Detailed list with hidden files
ls -la

# Detailed list with human-readable sizes
ls -lh

# Sort by modification time (newest first)
ls -lt

# Sort by file size (largest first)
ls -lS

# Reverse sort order
ls -lr

# All together: detailed, hidden, human-readable, sorted by time
ls -laht

Example — ls -lh output:

-rw-r--r-- 1 benjamin benjamin 1.5K Mar 10 08:00 .bashrc
-rw-r--r-- 1 benjamin benjamin  45M Mar 12 14:22 backup.tar.gz
drwxr-xr-x 2 benjamin benjamin 4.0K Mar 15 10:30 Desktop

Notice how 45M is much easier to read than 47185920.

List a specific directory

You don't have to be in a directory to list it:

ls -la /etc/
ls -lh /var/log/

Change Directory — cd

cd stands for Change Directory. It moves you to a different location.

Basic navigation

# Go to a specific directory
cd /home/benjamin/Documents

# Go to your home directory (three ways)
cd ~
cd $HOME
cd

# Go up one level
cd ..

# Go up two levels
cd ../..

# Go to the previous directory (toggle back)
cd -

Practical examples

# Start from home
pwd
# Output: /home/benjamin

# Navigate to Documents
cd Documents
pwd
# Output: /home/benjamin/Documents

# Go up one level
cd ..
pwd
# Output: /home/benjamin

# Navigate to an absolute path
cd /var/log
pwd
# Output: /var/log

# Jump back to the previous directory
cd -
# Output: /home/benjamin

Tab completion

One of the most powerful features in the terminal is tab completion. Start typing a directory name and press Tab:

cd Doc[TAB]
# Autocompletes to: cd Documents/

cd /etc/apa[TAB]
# Autocompletes to: cd /etc/apache2/

If there are multiple matches, press Tab twice to see all options.


Directory Structure — tree

tree displays the directory structure as a visual tree.

Install tree (if not available)

sudo apt install tree

Basic usage

tree

Example output:

.
├── Documents
│   ├── notes.txt
│   └── project
│       ├── README.md
│       └── src
│           └── main.py
├── Downloads
│   └── image.png
└── Desktop
    └── shortcut.desktop

5 directories, 4 files

Limit depth

# Show only 1 level deep
tree -L 1

# Show 2 levels deep
tree -L 2

Show hidden files and directories only

# Include hidden files
tree -a

# Show only directories
tree -d

# Combine: directories only, 2 levels deep
tree -d -L 2

Absolute vs Relative Paths

Understanding paths is fundamental in Linux.

Absolute path

Starts from the root / — the full address:

cd /home/benjamin/Documents/project
cat /etc/hostname
ls /var/log/syslog

Relative path

Starts from your current position:

# If you are in /home/benjamin:
cd Documents/project    # relative: goes to /home/benjamin/Documents/project
cd ./Documents/project  # same thing (./ = current directory)
cd ../jane/Documents    # go up, then into jane's Documents

Special path symbols

Symbol Meaning Example
/ Root directory cd /
~ Home directory cd ~/Documents
. Current directory ./script.sh
.. Parent directory cd ../..
- Previous directory cd -

Exercises

Exercise 1: Explore your system

# 1. Print your current directory
pwd

# 2. List all files (including hidden) in your home directory
ls -la ~

# 3. Navigate to /etc and list its contents
cd /etc
ls

# 4. Go back to your home directory
cd ~

# 5. Check where you are
pwd

Exercise 2: Navigate a path

# 1. Go to /var/log
cd /var/log

# 2. List files sorted by modification time
ls -lt

# 3. Go up two directories
cd ../..

# 4. Where are you now?
pwd
# Expected: /

# 5. Go home with one command
cd

Exercise 3: Explore with tree

# 1. Show your home directory structure (2 levels)
tree -L 2 ~

# 2. Show only directories in /etc (1 level)
tree -d -L 1 /etc

# 3. Count files in your home directory
tree ~ | tail -1

Key Takeaways

  • pwd — always know where you are
  • ls -la — your go-to command for listing files
  • cd — navigate with absolute or relative paths
  • Tab — your best friend for auto-completion
  • cd - — quickly toggle between two directories

Next Lesson: Lesson 2: File Operations →