Key Takeaway:
This cheat sheet puts the Linux terminal commands you’ll use every day on one page, grouped by the job you’re trying to do: moving around, handling files, searching, permissions, installing software and checking your network. Each group has a short note on the part beginners get wrong, and a free hands-on lesson if you want to practise. The whole thing is also a two-page PDF you can print and keep next to your keyboard.
The terminal is hard at the start for one reason: nobody tells you the words. Once you know that pwd means “where am I” and grep means “find this text”, most of it stops being mysterious. Everything below works in the terminal on Ubuntu, Linux Mint, Debian, Raspberry Pi OS and most other Linux systems. On a Mac, the file and search commands work the same way, but apt, ip, ss and free don’t exist there.
📄 Want it on paper? Download the printable cheat sheet (PDF, two pages). ItIt prints on both Letter and A4 paper.#8217;s Letter size; on A4 paper, choose It prints on both Letter and A4 paper.#8220;Fit to pageIt prints on both Letter and A4 paper.#8221; when printing.
🧭 Getting around
| Command | What it does |
|---|---|
pwd | where am I |
ls | list files |
ls -la | all files, detailed |
ls -lh | readable file sizes |
cd dir | enter folder |
cd .. | up one level |
cd ~ | home folder |
cd - | previous folder |
clear | clear the screen |
Files whose names start with a dot are hidden, which is why plain ls misses them and ls -la doesn’t. cd - jumps straight back to wherever you were before.
Practise it: Linux Files and Folders: Find Your Way Around, a free hands-on lesson.
Files & folders
| Command | What it does |
|---|---|
mkdir name | make folder |
mkdir -p a/b/c | make nested folders |
touch file | make empty file |
cp a b | copy file |
cp -r a b | copy folder |
mv a b | move or rename |
rm file | delete, no undo |
rm -r dir | delete folder |
rm -i file | delete, but ask first |
There is no recycle bin in the terminal. rm deletes immediately and permanently, so use rm -i, which asks before each file, while you’re learning. mv both moves and renames: moving a file to a new name in the same folder is how you rename it.
Practise it: Create, Move and Delete Files Safely, a free hands-on lesson.
Reading & editing
| Command | What it does |
|---|---|
cat file | print whole file |
less file | scroll it (q quits) |
head -20 file | first 20 lines |
tail -20 file | last 20 lines |
tail -f log | follow it live |
nano file | edit (Ctrl+O save, Ctrl+X exit) |
wc -l file | count lines |
file thing | what type is it |
Use cat for short files and less for long ones. tail -f keeps printing new lines as they’re added to a log; press Ctrl+C to stop it.
Searching
| Command | What it does |
|---|---|
grep "x" f | find lines in a file |
grep -i "x" f | ignore capitals |
grep -n "x" f | with line numbers |
grep -r "x" . | search all files below |
grep -v "x" f | lines NOT matching |
find . -name "*.txt" | find by name |
find . -size +10M | find big files |
which prog | where a program lives |
The two get mixed up constantly: grep looks inside files for text, while find looks for files by name, size or date.
Practise it: Linux Pipes for Beginners: Search and Filter With grep, a free hands-on lesson.
Pipes & redirection
| Command | What it does |
|---|---|
a | b | feed a’s output to b |
cmd > file | save output (overwrite) |
cmd >> file | append output |
cmd 2>/dev/null | discard errors |
cmd | tee file | screen AND file |
sort | sort lines |
uniq | remove duplicates |
wc -l | count lines |
One arrow replaces the whole file without asking; two arrows add to the end. Read the pipe as the word “then”: ls -la | grep log | wc -l lists the files, then keeps the ones containing “log”, then counts them.
Practise it: Linux Pipes for Beginners: Search and Filter With grep, a free hands-on lesson.
Wildcards
| Command | What it does |
|---|---|
* | any characters |
? | exactly one character |
[abc] | any one of these |
{a,b} | either whole option |
Before you delete with a wildcard, run the same pattern with ls first, so you see exactly which files it matches.
🔐 Permissions
| Command | What it does |
|---|---|
chmod +x file | make runnable |
chmod 644 file | normal file |
chmod 755 dir | normal folder/script |
chmod 600 file | private to me |
chown u:g file | change owner |
whoami | who am I |
sudo cmd | run as admin |
sudo !! | redo last cmd with sudo |
In the numbers, read is 4, write is 2 and execute is 1, added up for the owner, the group and everyone else: 644 is owner read+write, everyone else read only. Never fix a permission error with chmod 777, which gives everyone on the system full rights.
Practise it: Linux Permissions and sudo Explained, a free hands-on lesson.
Packages (apt)
| Command | What it does |
|---|---|
sudo apt update | refresh catalogue |
sudo apt upgrade | update everything |
apt search x | find a package |
apt show x | details |
sudo apt install x | install |
sudo apt remove x | uninstall |
sudo apt autoremove | clean leftovers |
apt is the package manager on Ubuntu, Linux Mint, Debian and Raspberry Pi OS. Fedora uses dnf and Arch uses pacman; the idea is the same. Run update before install so the catalogue is current.
Processes & system
| Command | What it does |
|---|---|
ps aux | everything running |
top / htop | live view (q quits) |
kill PID | stop a process |
kill -9 PID | force stop |
pkill name | stop by name |
df -h | disk space |
du -sh * | size of each item |
free -h | memory in use |
uptime | time since reboot |
Try a plain kill first, which asks the program to close itself. kill -9 stops it without letting it save anything, so keep it for programs that won’t respond.
🌐 Networking
| Command | What it does |
|---|---|
ip a | my addresses |
ip r | routing / gateway |
ping -c 4 host | test reachability |
dig domain | DNS lookup |
curl ifconfig.me | my public IP |
ss -tulpn | what’s listening |
wget url | download a file |
curl ifconfig.me asks an outside service for your public IP; our What Is My IP checker shows the same thing in a browser. To read what ss -tulpn prints, see How to Check Open Ports.
Practise it: Linux Network Commands: ip, ping, curl and ss, a free hands-on lesson.
Archives
| Command | What it does |
|---|---|
tar -xzf f.tar.gz | extract |
tar -czf f.tar.gz d | create |
unzip f.zip | extract a zip |
The tar letters stand for extract or create, gzip compression, and file name next.
⌨️ Keyboard survival
| Command | What it does |
|---|---|
Tab | autocomplete, use it |
↑ ↓ | previous commands |
Ctrl + R | search history |
Ctrl + C | stop running program |
Ctrl + L | clear screen |
Ctrl + A / E | start / end of line |
q | quit man pages, less |
Esc :q! | escape from vim |
If you remember only three things: Tab finishes what you’re typing, Ctrl+C stops anything that’s running, and sudo runs a command as administrator, which is what most “permission denied” errors on system files need.
Practise it: Your First Linux Commands, a free hands-on lesson.
Getting help
| Command | What it does |
|---|---|
man cmd | full manual |
cmd --help | quick summary |
apropos word | find related commands |
--help is the quick version and man the full manual; press q to leave it.
⚠️ The Commands That Can Hurt You
Almost everything on this page only looks at things or makes small, reversible changes. These are the exceptions, and they’re worth a second’s thought every time:
rmandrm -rdelete for good. There’s no recycle bin and no undo.- Any
rm -rfyou copied from a website. It deletes everything it’s pointed at without asking. Never paste one from a source you don’t trust. chmod 777“fixes” a permission error by removing the protection completely. Work out who actually needs access instead.>instead of>>wipes the file you’re writing to before it writes anything.sudoin front of anything you don’t understand. It runs the command with full administrator rights, so a mistake can reach the whole system.
Where This Cheat Sheet Comes From
These are the two cheat-sheet pages from the back of our book Linux Terminal for Absolute Beginners: Forty Commands and the Confidence to Use Them, available on Kindle and in paperback. The book explains each command from scratch, with a “Try it” exercise in most chapters and the risky ones kept in a scratch folder where they can’t do harm. If you’d rather learn for free, the Linux and the Command Line course covers the same ground in seven hands-on lessons, some with a practice terminal in the page.
Frequently Asked Questions
Do these commands work on a Mac?
Most of them. macOS has a terminal with the same file, search, pipe and permission commands. What’s missing is the Linux-specific part: apt, ip, ss and free don’t exist on a Mac, and some options differ slightly.
What’s the difference between > and >>?
One arrow, >, replaces everything in the file with the new output. Two arrows, >>, add the new output to the end and keep what was there. When in doubt, use two.
I’m stuck inside a program and can’t get out. What do I press?
Try them in this order: q (for less, man and top), Ctrl+C (for anything still running), and Esc then :q! then Enter (for the vim editor). In nano, Ctrl+X exits.
My distribution doesn’t have apt. What do I use?
Fedora uses dnf (sudo dnf install x) and Arch uses pacman (sudo pacman -S x). Everything else on this page works the same across distributions.
Is it safe to practise these on my own computer?
The commands that only look at things, such as pwd, ls, cat, grep and ip a, can’t change anything. For the rest, practise inside /tmp, a scratch folder that most Linux systems empty when they restart, and use rm -i until deleting feels routine.