01The two safety rules
Never run a command you found online without knowing what it does. Every command on this site carries a "what this does" note. Hold the rest of the internet to the same standard. If a stranger's fix starts with curl piped into bash, walk away.
Treat sudo like a chainsaw: fantastic tool, deserves a breath before you pull the cord. Plain commands mostly can't hurt the system. sudo ones can. So those are the ones you read twice, especially anything containing rm.
That's it. Follow those two and the terminal is about as dangerous as a spreadsheet.
02Anatomy of a command
ls -l /home
Read it as three parts: ls = the verb ("list"). -l = an option changing how ("long, detailed format"). /home = the noun it acts on (a folder). Verb, adverbs, noun. Every command you'll ever see is this sentence.
Two mechanical tips that make you 10× faster: press Tab to auto-complete file names (press it twice to see options), and press ↑ to bring back your previous commands instead of retyping them.
03Looking around
pwd
What this does: prints the folder you're standing in ("print working directory"). The terminal always has a location, like a file manager window.
ls
What this does: lists what's in the current folder. Add -a to also show hidden files (the ones starting with a dot).
cd Documents
What this does: moves you into the Documents folder ("change directory"). cd .. goes up one level; plain cd takes you home.
cat notes.txt
What this does: prints a text file to the screen. For long files use less notes.txt. Scroll with the arrows and, crucially, press q to leave.
04Moving things
cp report.pdf backup-report.pdf
What this does: copies a file (source first, destination second). The original stays put.
mv report.pdf Documents/
What this does: moves a file into a folder. Renaming is the same verb: mv old-name.txt new-name.txt.
mkdir projects
What this does: makes a new folder called projects right where you are.
rm draft.txt
What this does: deletes a file, permanently, no recycle bin. This is the one command in the kit worth double-checking every single time. Rule two applies with feeling.
05Superpowers (sudo)
sudo apt update && sudo apt upgrade
What this does: on Ubuntu/Mint/Debian. Refreshes the list of available updates, then installs them. && means "and if that worked, then". Fedora folks: sudo dnf upgrade. This is 90% of everyone's sudo usage.
sudo means "do this as the administrator." It asks for your password (typing shows nothing. Normal), remembers you for a few minutes, and logs what you did. It's a key, not a cheat code: only put it in front of commands you understand.
06Getting unstuck
- Something's running forever: Ctrl+C cancels it. This is the terminal's most-pressed chord.
- Screen fills with a pager you can't leave: press q.
- Accidentally in a text editor called vim: press Esc, type
:q!, press Enter. You are now part of a very large club. - Want the manual:
man lsshows the manual for any command (q to exit. See the pattern?). - Terminal looks garbled: type
resetand press Enter. Cosmetic, always safe.
That's the whole kit: twelve commands and a couple of escape hatches. Print the cheat sheet, keep it near the keyboard, and let the black box become furniture.