# Terminal Fundamentals

## Opening Your Terminal

First things first

### Mac

Press `Cmd + Space` to open Spotlight, type **Terminal**, and hit Enter. That's it.

Other options: iTerm2 or Wezterm (if you've installed them). They all do the same thing.

### Windows (WSL)

Open the Start menu, type **Ubuntu** (or **WSL**), and hit Enter. You should see a dark window with a blinking cursor.

If you don't have WSL installed, see the [Environment Installation guide](installation.html) first.

### Windows (Git Bash) — Quick Start

If you don't have WSL set up yet, **Git Bash** is a quicker alternative to get started learning the terminal. Download it from [git-scm.com/downloads/win](https://git-scm.com/downloads/win), install with the default options, then open the Start menu, type **Git Bash**, and hit Enter.

Git Bash and WSL both use the same commands (Bash). Everything in this guide works identically in either one. For a full dev environment, we recommend [setting up WSL](installation.html) when you're ready — but Git Bash is perfect for learning the fundamentals.

The terminal is just a text-based way to talk to your computer. Instead of clicking folders, you type commands. Everything you can do by clicking, you can do here -- faster.

1

## Finding Your Way

~10 minutes · Absolute beginner

### 01 `pwd` -- Where am I?

Prints the full path of the folder you're currently in (your "working directory").

```
pwd
```

/home/yourname

On Mac you'll see something like `/Users/yourname`

### 02 `ls` -- What's here?

Lists the files and folders in your current directory.

```
ls
```

Desktop Documents Downloads Pictures

You'll see your own folders listed here.

For more detail (hidden files, permissions, sizes), add `-la`:

```
ls -la
```

drwxr-xr-x 5 you you 4096 Feb 26 10:00 .  
drwxr-xr-x 3 you you 4096 Feb 26 09:00 ..  
-rw-r--r-- 1 you you 220 Feb 26 09:00 .bashrc  
drwxr-xr-x 2 you you 4096 Feb 26 10:00 Desktop

Files starting with `.` are hidden files. `-la` shows them.

### 03 `cd` -- Moving around

Changes your current directory. Think of it as double-clicking a folder.

Go into a folder:

```
cd Desktop
```

Go up one level (back to the parent folder):

```
cd ..
```

Go straight to your home folder from anywhere:

```
cd ~
```

`~` is a shortcut that always means "my home folder." You'll see it everywhere.

Where is "home" on different systems?

- **Mac:** `/Users/yourname`
- **Linux:** `/home/yourname`
- **WSL:** `/home/yourname` — this is inside the Linux filesystem, *not* your Windows user folder. To access Windows files from WSL, use `/mnt/c/Users/yourname`
- **Git Bash:** `/c/Users/yourname` (your normal Windows home)

If you save a file on your Windows desktop but can't find it in WSL, that's why — they're separate filesystems. Use `/mnt/c/` to bridge them.

### 04 `mkdir` -- Creating folders

Creates a new folder (directory).

```
mkdir my-project
```

No output means it worked. Run `ls` to see your new folder.

### 05 `touch` -- Creating files

Creates a new empty file.

```
touch hello.txt
```

No output means it worked. Run `ls` to confirm the file exists.

### 06 `clear` -- Clean the screen

Clears all the text from your terminal. Your files are untouched -- it just tidies up the view.

```
clear
```

Your terminal will be blank. Scroll up if you need to see previous output.

### Practice Exercise: Build a project folder

Copy and paste each command one at a time. After each one, look at what happened before moving to the next.

```
cd ~
```

```
mkdir terminal-practice
```

```
cd terminal-practice
```

```
pwd
```

```
mkdir src
```

```
mkdir docs
```

```
touch README.md
```

```
touch src/app.js
```

```
touch docs/notes.txt
```

```
ls
```

```
ls src
```

```
ls docs
```

```
tree
```

README.md docs src  
  
.  
├── README.md  
├── docs  
│ └── notes.txt  
└── src  
└── app.js

`tree` shows your entire folder structure at a glance. You just built all of this from the terminal.

2

## Working With Files

~15 minutes · Getting comfortable

Make sure you completed the Level 1 exercise. We'll keep working in the `~/terminal-practice` folder.

### 01 `echo` -- Writing text to files

Writes text into a file. The `>` symbol means "put this into that file" (overwrites). `>>` means "add to the end."

```
echo "Hello from the terminal" > README.md
```

```
echo "This is line two" >> README.md
```

First command writes. Second command appends. No output is normal.

### 02 `cat` -- Reading files

Prints the entire contents of a file to your screen.

```
cat README.md
```

Hello from the terminal  
This is line two

### 03 `cp` -- Copying files

Makes a copy of a file. Original stays untouched.

```
cp README.md docs/README-backup.md
```

Run `ls docs` to see the copy.

### 04 `mv` -- Moving and renaming

Moves a file to a new location. Also used to rename files.

Rename a file:

```
mv docs/notes.txt docs/session-notes.txt
```

Move a file to a different folder:

```
touch temp.txt
mv temp.txt src/
```

Run `ls src` to see `temp.txt` moved there.

### 05 `rm` -- Deleting files

Permanently deletes a file. There is no trash can -- it's gone for good.

```
rm src/temp.txt
```

Be careful with `rm`. Double-check the file name before pressing Enter. Never run `rm -rf /` -- that would try to delete your entire system.

### 06 `grep` -- Searching inside files

Finds lines in a file that contain a specific word or phrase.

```
grep "terminal" README.md
```

Hello from the terminal

Shows every line that contains the word "terminal."

### 07 Pipes `|` -- Chaining commands

The pipe `|` sends the output of one command into the next command. Think of it as a conveyor belt.

```
ls | grep ".md"
```

README.md

Lists files, then filters to only show ones containing ".md".

### 08 `which` -- Where do programs live?

Shows the file path of a program. Useful for confirming something is installed.

```
which git
```

/usr/bin/git

If nothing shows up, that program isn't installed (or isn't in your PATH).

### 09 `echo $PATH` -- Environment variables

Environment variables are settings your terminal knows about. `$PATH` is the most important one -- it's the list of folders where your computer looks for programs.

```
echo $PATH
```

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

A colon-separated list of folders. When you type `git`, your computer checks each of these folders for a program called `git`.

### Practice Exercise: Write and search a file

Build a small file, then search through it. Copy each command one at a time.

```
cd ~/terminal-practice
```

```
echo "apples" > groceries.txt
```

```
echo "bananas" >> groceries.txt
```

```
echo "apple juice" >> groceries.txt
```

```
echo "bread" >> groceries.txt
```

```
echo "almond milk" >> groceries.txt
```

```
cat groceries.txt
```

```
grep "apple" groceries.txt
```

```
cat groceries.txt | grep "a"
```

apples  
apple juice

The `grep "apple"` command finds both lines containing "apple." The piped version finds all lines containing "a."

3

## Power User

~15 minutes · Stretch goals

### 01 Tab completion and arrow keys

These two habits will save you hours. They don't require copy-pasting -- just practice.

#### `Tab`

Start typing a file or folder name, then press Tab. The terminal auto-completes it. Try typing `cd Doc` then pressing Tab.

#### `Up Arrow`

Press the up arrow to cycle through your previous commands. Much faster than retyping.

### 02 `Ctrl+C` -- Stop everything

If something is running and you want it to stop, press `Ctrl+C`. It cancels the current command. This is your emergency brake.

Works for: stuck commands, running servers, accidental infinite loops. You'll use this daily.

### 03 `&&` -- Chaining commands

Run multiple commands in sequence. The second command only runs if the first one succeeds.

```
mkdir new-project && cd new-project && pwd
```

/home/yourname/terminal-practice/new-project

Creates the folder, moves into it, and prints the path -- all in one line.

### 04 Keyboard shortcuts

These work in most terminals. Practice them while typing commands.

`Ctrl+A` Jump to the beginning of the line

`Ctrl+E` Jump to the end of the line

`Ctrl+W` Delete the word before the cursor

`Ctrl+L` Clear the screen (same as `clear`)

`Ctrl+R` Search through your command history (type to search, Enter to run)

### 05 `chmod` -- File permissions

Controls who can read, write, or execute a file. You'll mostly use this to make scripts runnable.

```
echo '#!/bin/bash
echo "Hello from my script!"' > my-script.sh
chmod +x my-script.sh
./my-script.sh
```

Hello from my script!

`chmod +x` makes the file executable. `./` means "run this file from the current folder."

### 06 `alias` -- Creating shortcuts

Creates a shortcut for a longer command. Only lasts for the current terminal session.

```
alias ll="ls -la"
ll
```

Now typing `ll` does the same thing as `ls -la`. To make it permanent, add the alias line to your `~/.bashrc` or `~/.zshrc` file.

### 07 `ssh` -- Connecting to remote machines

Opens a terminal session on another computer. You'll use this when you have a server to manage.

```
ssh username@server-address
```

You'll be asked for a password (or it will connect automatically if you've set up SSH keys). Type `exit` to disconnect.

Don't worry if you don't have a server to SSH into. This is a "good to know" command for later.

### Practice Exercise: Put it all together

Create a mini project using everything you've learned. One command at a time.

```
cd ~ && mkdir my-first-app && cd my-first-app
```

```
mkdir src tests docs
```

```
echo "# My First App" > README.md
```

```
echo "Built from the terminal." >> README.md
```

```
echo 'console.log("hello world");' > src/index.js
```

```
echo 'print("hello world")' > src/main.py
```

```
echo "TODO: write tests" > tests/placeholder.txt
```

```
cat README.md
```

```
ls -la src/
```

```
grep "hello" src/index.js src/main.py
```

```
echo '#!/bin/bash
echo "Build complete!"' > build.sh
```

```
chmod +x build.sh
```

```
./build.sh
```

\# My First App  
Built from the terminal.  
...  
src/index.js:console.log("hello world");  
src/main.py:print("hello world")  
Build complete!

You just created a full project structure, wrote files, searched them, and ran a script -- all without leaving the terminal.

Level 4

## Why This Is Powerful

Watch the terminal do in seconds what would take minutes by hand

### 01 Wildcards -- Select dozens of files instantly

The `*` character means "anything". Instead of moving files one by one, you match patterns.

Let's create a mess, then clean it up in one command.

```
cd ~ && mkdir wildcard-demo && cd wildcard-demo
touch report.md notes.md todo.md
touch photo.png screenshot.png logo.png
touch data.csv results.csv
touch random.txt junk.log
ls
```

data.csv junk.log logo.png notes.md photo.png random.txt report.md results.csv screenshot.png todo.md

10 files, all mixed together. Now watch:

```
mkdir docs images data
cp *.md docs/
cp *.png images/
cp *.csv data/
tree
```

.  
├── data  
│ ├── data.csv  
│ └── results.csv  
├── docs  
│ ├── notes.md  
│ ├── report.md  
│ └── todo.md  
├── images  
│ ├── logo.png  
│ ├── photo.png  
│ └── screenshot.png  
├── ...

3 commands sorted 8 files into folders. Imagine doing that with 800 files -- same 3 commands.

### 02 For loops -- Do repetitive work automatically

The terminal can repeat commands for you. Let's simulate a real scenario: you have a folder full of files from different years, and you only want this year's files.

```
cd ~ && mkdir loop-demo && cd loop-demo

# Create 20 fake files from different years
for year in 2023 2024 2025 2026; do
  for i in 1 2 3 4 5; do
    touch "${year}-report-${i}.pdf"
  done
done

ls
```

2023-report-1.pdf 2024-report-1.pdf 2025-report-1.pdf 2026-report-1.pdf  
2023-report-2.pdf 2024-report-2.pdf 2025-report-2.pdf 2026-report-2.pdf  
... (20 files total)

20 files. You only want the 2026 ones. One command:

```
mkdir this-year
cp 2026* this-year/
ls this-year/
```

2026-report-1.pdf 2026-report-2.pdf 2026-report-3.pdf 2026-report-4.pdf 2026-report-5.pdf

Done. All 2026 files copied, nothing else touched. The `2026*` wildcard matched only files starting with "2026".

### 03 `curl` -- Grab things from the internet

`curl` fetches content from a URL, right in your terminal. No browser needed.

```
# Fetch a webpage and see the raw HTML
curl -s https://example.com | head -20

# Download a file
curl -o test.html https://example.com
ls -la test.html
```

You'll see raw HTML in your terminal. The `-s` flag means silent (no progress bar), and `head -20` shows just the first 20 lines.

**Security note:** You'll sometimes see install instructions like `curl ... | bash`. This downloads a script and runs it immediately. It's convenient, but you're trusting that URL with full access to your machine.

Only run `curl | bash` from sources you trust. When in doubt, download first (`curl -o script.sh URL`), read the file (`cat script.sh`), then run it. For more on staying safe, see the [Security guide](security.html).

### The point

Everything above took seconds. Sorting 20 files by year. Organising a messy folder by file type. Downloading from the internet. These aren't toy examples -- this is what the terminal does every day.

When you're building apps with Claude Code, every command happens in the terminal. The more comfortable you are here, the faster you build.

## Quick Reference

| Command | What it does              | Example                            |
|---------|---------------------------|------------------------------------|
| pwd     | Print working directory   | pwd                                |
| ls      | List files                | ls -la                             |
| cd      | Change directory          | cd ~/projects                      |
| mkdir   | Create folder             | mkdir my-project                   |
| touch   | Create empty file         | touch file.txt                     |
| cat     | Read file contents        | cat README.md                      |
| cp      | Copy file                 | cp a.txt b.txt                     |
| mv      | Move/rename file          | mv old.txt new.txt                 |
| rm      | Delete file (permanent!)  | rm file.txt                        |
| grep    | Search in files           | grep "word" file.txt               |
| echo    | Print/write text          | echo "hi" \> file.txt              |
| chmod   | Change permissions        | chmod +x script.sh                 |
| ssh     | Connect to remote machine | ssh user@host                      |
| tree    | Show folder structure     | tree                               |
| \*      | Wildcard (match anything) | cp \*.md docs/                     |
| curl    | Fetch URL content         | curl -s https://example.com        |
| for     | Loop over items           | for f in \*.txt; do echo \$f; done |

