Learning Objectives
  • Explain how the shell relates to the keyboard, screen, OS, and user programs
  • Explain when and why to use command-line interfaces instead of GUIs
  • Explain the difference between a file and a directory
  • Translate between absolute and relative paths
  • Use options and arguments to change command behavior
  • Use tab completion effectively
Setup
The Shell Prompt

Open your terminal. You should see a prompt — this means the shell is ready for input.

bash
$ |        # The prompt — hey, it's working!
$ ls       # List files in the current directory (your home directory)
$ pwd      # Print working directory — where are you?
Windows users

If you're using WSL, navigate to your Windows files with: cd /mnt/c/<your username>

Navigating Directories

cd (change directory) is the most-used command you'll learn today. Master it.

bash
$ cd /             # Go to the root of the filesystem
$ cd               # Shortcut: go back to your home directory
$ cd ~/            # Same thing — ~ always means home
$ cd Desktop/shell-lesson-data/exercise-data
Tab complete — use it constantly

Press Tab after typing the first few letters of a path. The shell completes it for you. If nothing happens, press Tab twice to see all options. Try misspelling something to see what the error looks like: cd Desktap/shell-lesson-data

Moving Up and Around

bash
$ cd ..            # Move up one directory level
$ cd exercise-data # Move into a subdirectory
$ cd -             # Go back to the previous directory
Problem — predict the outcome

What directory will this move you to? cd ../..
Come up with two ways to navigate back to the directory containing the workshop data.

Up and down arrows

Use the up/down arrow keys to scroll through your command history — you don't have to retype commands.

Listing Files and Using Flags

Flags modify how a command behaves. They start with a dash -.

bash
$ ls -l            # Long format — shows permissions, size, date
$ ls -lF           # Adds "/" after directory names
$ ls -lah          # Long format, all files (including hidden), human-readable sizes
$ clear            # Clear the terminal screen
$ man ls           # Read the manual for ls — press q to exit
Problem #1

Use the manual (man ls) to determine how to add color to the output of ls. Answer: ls -G

Pipes, Wildcards, and Viewing Files

The real power of Unix comes from combining commands. The pipe | sends the output of one command into the input of another.

bash
$ ls -F | grep \/ > directories.txt
# | pipes output into grep (a search tool)
# grep \/ searches for "/" (i.e., directories)
# > writes the output to a new file called directories.txt

Viewing File Contents

bash
$ head directories.txt      # Show first 10 lines
$ tail directories.txt      # Show last 10 lines
$ less directories.txt      # Scroll through the file (press q to exit)
$ more directories.txt      # Similar to less

Wildcards

The wildcard * matches any number of characters. Navigate to ~/Desktop/shell-lesson-data/north-pacific-gyre and try:

bash
$ wc -l NENE01736A.txt      # Count lines in one file
$ wc -l *.txt               # Count lines in ALL .txt files

Absolute vs. Relative Paths

bash
$ cd ~/Desktop/shell-lesson-data
$ head -5 exercise-data/directories.txt   # relative path — works
$ head -5 directories.txt                 # why doesn't this work?
$ head -5 ~/Desktop/shell-lesson-data/exercise-data/directories.txt  # absolute path
$ rm directories.txt                      # remove the file when done
Ask AI to Explain a Pipeline AI

Pipelines can be hard to read at first. Use AI to break them down. Try this prompt:

Try this prompt in Claude or ChatGPT
I'm learning Unix shell commands. Can you explain what this pipeline does, step by step? ls -F | grep \/ > directories.txt Please explain each part: what ls -F does, what the pipe | does, what grep \/ does, and what > directories.txt does.

Then try modifying the command — ask AI what would happen if you changed \/ to something else, or used >> instead of >.

Before Day 2

Make sure you have shell-lesson-data on your Desktop. We'll re-download it fresh at the start of Day 2.