The Terminal, levelled up

You know the basics — now for the real power. Chain commands into pipelines, search and reshape text, write scripts that automate the boring, manage permissions and processes, and SSH properly with keys. With a pipeline-capable practice terminal to play in.

Part 1 · Lesson 1

Pipes | — the idea that changes everything

This one concept is what makes the Terminal genuinely powerful. A pipe (the | character, Shift-backslash on a Mac) takes the output of one command and feeds it straight into the next as its input. You build a little assembly line.

$ cat server.log | grep error | wc -l 3

Read left to right: “print the log → keep only lines with ‘error’ → count them.” Three simple tools, combined, answer a real question in one line: how many errors are in this log?

Pipes are a factory conveyor belt. Each machine does one small job and passes the result along. No single tool is clever — the chain is. This is the whole philosophy of the command line: small sharp tools, joined up.
Takeaway: | feeds one command’s output into the next. Chain small tools to answer big questions in a single line.
Part 1 · Lesson 2

Redirection, and catching errors

You met > in the beginner course (send output into a file). Here’s the fuller set:

Every command actually has two output taps: normal results and error messages. Usually they both hit the screen, but you can direct each wherever you like — handy when saving a job’s output or its errors for later.

Takeaway: > writes, >> appends, < feeds in, and 2> catches errors separately. Output has two taps: results and errors.
Part 1 · Lesson 3

Wildcards — acting on many files at once

Wildcards let one command hit lots of files. The shell expands them before the command runs:

Respect * with rm. rm * deletes everything in the folder. And a stray space — rm * .txt instead of rm *.txt — is famously how people wipe a whole folder by accident. Type wildcards with ls first to see what they’ll match, then swap in the real command.
Takeaway: *, ? and [ ] match many files at once. Preview with ls before doing anything destructive.
Part 2 · Lesson 4

grep — find a needle in any haystack

grep searches for lines containing some text — in a file, or in whatever’s piped into it. It’s probably the command you’ll reach for most.

$ grep "timeout" server.log # lines containing timeout $ grep -i "error" server.log # -i = ignore upper/lower case $ grep -v "ok" server.log # -v = invert: lines WITHOUT ok $ grep -c "error" server.log # -c = just count matches

Its real power shows on the end of a pipe: ls | grep report finds files with “report” in the name; history | grep ssh finds every ssh command you’ve run. Anything that produces lines, grep can sift.

Takeaway: grep pattern file finds matching lines; -i ignores case, -v inverts, -c counts. Superb on the end of a pipe.
Part 2 · Lesson 5

find — locate files anywhere

grep looks inside files; find locates the files themselves, by name, type, size or age, searching down through every sub-folder.

$ find . -name "*.pdf" # every PDF from here down $ find . -type d -name "backup" # folders (d) called backup $ find . -size +100M # files bigger than 100 MB $ find . -mtime -7 # changed in the last 7 days

The . means “start here, in the current folder.” find is how you answer “where on earth did I put that file?” or “what’s eating all my disk space?”

Takeaway: find . -name "…" hunts down files by name/type/size/age through every sub-folder. grep searches inside; find searches for.
Part 2 · Lesson 6

The text toolkit — then build a pipeline live

A few more small tools that shine in pipelines:

Now try it for real. This practice terminal understands pipes and all of the above. There’s a server.log and a names.txt waiting. Follow the steps — tap a command to drop it in, then press Return.

  1. See the log: cat server.log
  2. Find the errors: grep error server.log
  3. Count them in a pipeline: cat server.log | grep error | wc -l 🎉
  4. Bonus — tally the names: cat names.txt | sort | uniq -c
practice — pipelines
Try help, ls, ls *.txt, grep -c error server.log, NAME=Chris then echo hi $NAME.
Takeaway: wc, sort, uniq, head/tail are pipeline building blocks. sort | uniq -c is the classic “count how many of each.”
Part 3 · Lesson 7

Variables & the PATH

The shell can remember values in variables. Set one with NAME=value (no spaces around the =), and use it later with a $ in front:

$ NAME=Chris $ echo "Hello $NAME" Hello Chris

Some variables are set for you, and shared with programs you run — these are environment variables. The most important is PATH: the list of folders the shell searches to find commands. When you type ls, the shell looks through PATH to find the actual ls program.

$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin

export NAME=value makes a variable available to programs you launch, not just the shell itself. You’ll see export a lot in setup guides.

Takeaway: NAME=value stores a value; $NAME uses it. PATH is the list of places the shell looks to find commands.
Part 3 · Lesson 8

Make it yours: aliases & history tricks

An alias is a shortcut you invent for a longer command:

$ alias ll="ls -la" # now typing ll runs ls -la

Typed like that, it lasts only for this session. To keep it forever, add the line to your shell’s config file. On a modern Mac the shell is zsh, so that file is ~/.zshrc (older systems use ~/.bashrc). Edit it, add your aliases, save, and open a new Terminal — they’re always there.

And a few genuine time-savers:

Takeaway: alias makes shortcuts (save them in ~/.zshrc); Ctrl+R, !! and !$ save you huge amounts of typing.
Part 4 · Lesson 9

Your first script — automate the boring

A script is just a file with a list of commands, run top to bottom. Anything you can type, you can save and re-run forever. Create a file backup.sh containing:

#!/bin/bash echo "Backing up my site…" cp -r mysite mysite-backup echo "Done."

Two things make it work:

Then run it with ./backup.sh (the ./ means “the one right here”). From then on, one command does the whole job.

A script is a recipe card. You work out the steps once, write them down, and after that you just say “make that” — no thinking, no missed steps.
Takeaway: a script is a saved list of commands. Start it with #!/bin/bash, make it executable with chmod +x, run it with ./name.sh.
Part 4 · Lesson 10

Logic in scripts: loops & decisions

Scripts get powerful when they can repeat and decide. Two workhorses:

A loop — do something to each item:

for file in *.txt; do echo "Found: $file" done

A decision — do something only if a condition holds:

if [ -f "index.html" ]; then echo "The homepage exists." else echo "No homepage found!" fi

And command substitution — drop the result of one command into another with $(…):

echo "There are $(ls | wc -l) items here."
Takeaway: for…do…done repeats, if…then…fi decides, and $(command) drops one command’s result into another. That’s real automation.
Part 5 · Lesson 11

Permissions — who can do what

Every file carries permissions: who may read it, write (change) it, and execute (run) it. Run ls -l and each line starts with something like -rwxr-xr--. Tap the parts to decode it:

-rwxr-xr--

Tap a chunk above ↑

One type flag, then three groups of rwx: what the owner, the group, and everyone else is allowed to do.

You change them with chmod. The quick way uses numbers — chmod 755 file (owner can do everything, others can read & run) or chmod 644 file (owner read/write, others read). The friendly way: chmod +x script.sh just adds “executable.” On a server, permissions are how you keep private files private.

Takeaway: permissions are read/write/execute, for owner / group / everyone. chmod +x makes a script runnable; chmod 644/755 are the common presets.
Part 5 · Lesson 12

Processes — what’s running, and stopping it

Every running program is a process with a number (a “PID”). Sometimes you need to see them or stop one:

And running things in the background so your Terminal stays free:

Takeaway: top and ps show what’s running; kill PID stops it; & runs a job in the background so you can keep working.
Part 6 · Lesson 13

SSH keys — log in without a password, more securely

In the beginner course you connected with a password. The professional way is an SSH key: a matched pair of files — a private key that stays secret on your Mac, and a public key you put on the server. They only work as a pair, so it’s both more convenient and more secure than a password.

Set it up once:

$ ssh-keygen -t ed25519 # makes your key pair (press Return to accept defaults) $ ssh-copy-id chris@your-server # installs your PUBLIC key on the server

After that, ssh chris@your-server just lets you in — no password typed. Behind the scenes the two keys perform a secret handshake.

A key pair is a special padlock and its only key. You hand out copies of the open padlock (the public key) to any server you like. Only your single private key can close and open them — and it never leaves your Mac.
The golden rule of keys: your private key (usually ~/.ssh/id_ed25519, no .pub) is like the master key to your house. Never send it to anyone, never paste it anywhere, never put it on a server. Only ever share the .pub (public) one.
Takeaway: ssh-keygen makes a key pair; ssh-copy-id puts the public half on the server; then you log in with no password. Guard the private key with your life.
Part 6 · Lesson 14

Moving files to and from a server

SSH gets you a Terminal on the server. To move files across, two commands — they’re like cp, but one end is a remote machine:

$ scp index.html chris@server:/var/www/ # copy a file UP to the server $ scp chris@server:/var/log/app.log . # copy one DOWN to here (.)

For anything bigger — a whole website folder, or a repeated backup — use rsync. It’s smarter: it only copies what actually changed, so the second run is near-instant.

$ rsync -avz mysite/ chris@server:/var/www/mysite/

Two last power tools worth knowing exist, for when you’re ready:

Takeaway: scp copies single files to/from a server; rsync syncs whole folders efficiently. An ~/.ssh/config saves typing; tmux keeps long jobs alive.
Check yourself

A quick seven-question quiz

Instant feedback on each.

That’s advanced Terminal under your belt. Pipes, searching, scripts, permissions, processes and SSH keys — the toolkit real developers and sysadmins use every day. You’re genuinely capable at the command line now.