Module 6 · Command Line
The terminal is the black window where you type commands. It looks scary at first. It isn't. Every command in this module does something you already do on Windows — once you see which Windows thing each one matches, it stops being strange.
By the end of this module, you will:
- Execute at least 15 essential terminal commands from memory
- Navigate the filesystem, create, copy, move, and delete files via the terminal
- Use command flags and arguments to modify command behaviour
- Combine commands using pipes to filter and process output
- Use wildcards (*, ?, [abc], {a,b,c}) to operate on multiple files at once
- Chain commands with ;, &&, || and recall past commands with !!, !$, history
- Inspect files efficiently with head, tail, and less instead of cat
The Windows command, the Linux command — side by side
~ is shorthand for home. cd - sends you back to the folder you were just in.-p bit lets you make folders inside folders in one go: mkdir -p a/b/c.-r. Example: cp file.txt backup.txt makes a copy called backup.txt.mv old.txt new.txt renames old.txt to new.txt.-r means "and everything inside the folder". -f means "don't ask, just do it". Read what comes after this twice before pressing Enter.cat file1 file2 shows both, one after the other.grep -r "error" /var/log/ hunts for "error" in every log file at once.find ~ -name "*.pdf" finds every PDF anywhere in your home folder.man ls shows you everything ls can do. Press q to close it.sudo on the front any time a command needs admin power.Pipes and redirection — connecting commands together
The most dangerous command on Linux
sudo rm -rf / wipes everything on your computer — instantly. No warning. No undo. No Recycle Bin. Linux trusts you to know what you're doing. The rule: never copy a command off the internet and run it until you understand every part of it. If you're not sure, don't run it.
The dollar sign — don't type it
All through this course you'll see commands written like this: $ ls -la. The $ at the start is not part of the command. It's the little symbol your terminal shows to say "I'm ready, type something." Type only what comes after the $. Every new Linux person gets caught by this once. Now you won't.
echo "Hello Linux"You should see: Hello Linux
Two keys that save you most of the typing
These two shortcuts barely get mentioned in Linux books, but every experienced Linux user hits them all day. Learn them now and the rest of this course gets a lot easier.
Tab — let Linux finish the typing for you
clear, just faster.Try it: type cd /ho then hit Tab. Linux finishes it for you as cd /home/. Type the first letter of your username, hit Tab again, and you're at your home folder — without typing the whole path.
Wildcards — handle lots of files in one go
A wildcard is a special character that means "match a bunch of files at once". Linux swaps the wildcard for the matching filenames before the command runs. So rm *.tmp deletes every file in this folder ending in .tmp. Useful — and a little dangerous, because once it runs there's no undo. Always run ls with the same wildcard first to check what would be hit.
Four wildcards you'll use every week
ls *.pdf shows every PDF. rm log_* deletes every file whose name starts with "log_".ls report-?.txt matches report-1.txt and report-A.txt, but not report-10.txt (that's two characters).ls file[123].log matches file1.log, file2.log and file3.log.cp report.{txt,bak} is shorthand for "copy report.txt to report.bak".Try it: ls *.html in this course folder lists every HTML file. Now picture pairing that with grep, cp, or — carefully — rm.
Chaining commands, and history shortcuts
A pipe (|) sends the output of one command straight into the next one. Three more symbols join commands by result — "do this, then if it worked do that". And the history shortcuts pull back old commands without you typing them again.
Joining commands together
mkdir build && cd build — make the folder, then move into it (but only if the folder got made).fg.Bringing back what you typed before
sudo on the front? Type sudo !! and you're done.mkdir docs, type cd !$ and you move into docs.grep to find one: history | grep ssh.Reading big files — head, tail, less (not cat)
cat dumps the whole file onto your screen all at once. Fine for tiny files. Awful for a log file with 50,000 lines. These three commands are how experienced Linux people actually read files.
| Command | What it does | Useful extras |
|---|---|---|
head file | Shows the first 10 lines (handy for a CSV header). | head -20 file shows the first 20 lines. |
tail file | Shows the last 10 lines (handy for recent log entries). | tail -f file keeps watching the file and prints new lines as they appear. Brilliant for watching logs as something happens. |
less file | Lets you scroll through a huge file one page at a time. | Same keys as the man pages: Space to scroll, /word to search, q to quit, G to jump to the bottom. |
A real-world trick: open two terminals. Run tail -f /var/log/syslog in one. Do whatever you're debugging in the other. The system tells you what it's doing, live, as you do it.
Nano — a 30-second intro to a text editor
Some of the commands in this module save things to files (the >> ones). Soon you'll want to edit one of those files. Nano is the friendliest Linux text editor — it shows its shortcuts right at the bottom of the screen, so you never have to remember them. Four shortcuts is all you need to function:
The four nano commands you need right now
Module 13 covers nano and vim properly. This is enough to start.
The built-in instruction book — man pages
Every Linux command comes with its own instruction book. Type man ls to read the manual for the ls command. The manual opens in a special reader — the screen doesn't look like the normal terminal any more. Here's how to move around it:
Moving around a man page
/ then a word, press Enter. Press n to jump to the next match.Tip: when a man page feels like too much, type /EXAMPLE and jump straight to real working examples. Working commands are always easier to copy than long explanations.
Squashing files into one file — tar, gzip, zip
Sooner or later you'll want to bundle a whole folder into a single file — to email a project, back up a folder, or open something somebody else has packed up. On Windows you right-click and pick "Send to → Compressed (zipped) folder". On Linux it's a one-line command. Two words to know: archive (one file that contains lots of files) and compression (squashing that file to make it smaller). On Linux you usually do both in one go.
| What you want to do | Command | What's going on |
|---|---|---|
| Pack a folder into one squashed file (the everyday one) | tar -czf project.tar.gz project/ | c = create, z = squash with gzip, f = "the filename is next". .tar.gz is the standard Linux pack-and-squash format. |
| Open a .tar.gz back out | tar -xzf project.tar.gz | x = extract. The files land in the folder you're standing in. |
| Peek inside without unpacking it | tar -tzf project.tar.gz | t = list. Shows everything in the archive without unpacking. |
| Squash one single file | gzip notes.txt | Replaces notes.txt with notes.txt.gz. |
| Unsquash a .gz file | gunzip notes.txt.gz or gzip -d notes.txt.gz | The opposite of gzip. |
| Make a .zip (so a Windows person can open it) | zip -r project.zip project/ | Use this when you're sending the file to someone on Windows — Windows opens .zip on its own. For .tar.gz they'd need 7-Zip. |
| Open a .zip | unzip project.zip | Works the same on every Linux. |
Two other squashers you might bump into: bzip2 (older, slower, squashes a tiny bit smaller — file ends in .tar.bz2, swap the z flag for j) and xz (newer, slowest, smallest of all — file ends in .tar.xz, flag is J). For everyday work gzip is good enough. Only reach for the others when somebody hands you a file in that format.
du -sh ~/Documents · tar -czf docs-backup.tar.gz ~/Documents · du -sh docs-backup.tar.gz
Why Linux uses .tar.gz, not .zip
Back in the day, tar (short for "tape archive") just packed files together, and gzip just squashed them. Two simple tools, each doing one job. Sticking them together gives you .tar.gz. The good thing about this format: it remembers Unix file permissions and symlinks. .zip often loses those. So Linux software ships as .tar.gz, and .zip is reserved for sharing files with Windows users.