The Art of the Command Line
Move, inspect, manipulate text, investigate.
§ 01 Introduction
The jlevy/the-art-of-command-line repo is a gold mine: roughly 150 concentrated tips, validated by thousands of professionals. But it's also a wall of text with no path through it. If you're a beginner, you open the page, see 200+ commands dumped at once, and close the tab. A shame — the content is excellent.
This guide gives you a path. You won't read everything — you'll read the right order, at the right dose, with verifiable goals, across 4 tiers: survive, navigate, understand, investigate.
Who it's for: someone who will spend the rest of their life typing commands (ops, sysadmin, backend dev, homelabber) and wants to lay the foundations painlessly. This is level 0 of the learning path: everything else (Docker, Git, advanced SSH) starts here.
When it's NOT the right choice:
- You want a step-by-step video-style course — go for "Linux Journey" or a dedicated video channel instead.
- You want to learn Bash scripting in depth — this guide skims the surface, it doesn't dive.
- You've been comfortable on the CLI for 5+ years — you'll learn almost nothing here.
If any of those apply, skip this guide guilt-free: it isn't for you, and that's perfectly fine.
§ 02 What you'll learn
By the end of this path, you'll know how to:
- Navigate a Linux system without a mouse (and faster than with one).
- Inspect a file, a process, a disk, a network connection.
- Combine commands with pipes (
|) — the real Unix philosophy. - Manipulate text like a pro (
grep,sed,awkat the useful level). - Manage permissions without slapping
chmod 777everywhere (anti-pattern #1). - Master the basics you'll need later: redirections, exit codes, processes, environment variables, shell expansion.
§ 03 Prerequisites
You need:
- An accessible terminal: native Linux, macOS, or WSL2 on Windows. If you don't have one → install Ubuntu through WSL2 (10 minutes, Microsoft Store).
- A text editor you know how to open and close —
nanois enough, it's installed everywhere, and that's what we'll start with. - One free hour to get going, plus the patience to experiment.
Why no serious technical prerequisite? This guide is level 0 of your learning path. Everything starts here — no other guide is required first.
§ 04 Concepts
The shell rests on one simple, brilliant idea: everything is a text stream. Every command reads an input (stdin), writes an output (stdout), and reports errors on a separate channel (stderr). Because these streams are standardized, you can plug one command's output into the next command's input with a pipe (|), or divert it to a file with a redirection (>, >>, 2>).
That's the Unix philosophy: small tools that each do one thing well, composed into pipelines.
Key takeaways:
stdin/stdout/stderr: three streams per command. A pipe only carriesstdout;stderrkeeps going to your screen (unless you redirect it with2>).>overwrites,>>appends. Mixing them up empties a file — more on that in the pitfalls.- Exit code: every command finishes with a number (
0= success, anything else = error).echo $?shows it;&&and||use it to chain commands. - Shell expansion (
*,{1..10},$VAR) happens in the shell, before the command runs — the command never sees the*, it receives the expanded file list. - The path: the repo is split into sections (Basics, Everyday use, Processing files and data, System debugging…). We do not read it in order — we follow 4 tiers, each unlocking the next. At every tier: read the section, try every command in your terminal, do the mini-challenge.
§ 05 Walkthrough
step-01
Goal. Tier 1 — Survive. Read the repo's "Basics" section, trying every command in your terminal.
🤔 Why? You walk away with the vital essentials: knowing where you are (pwd), moving (cd), seeing (ls), creating/deleting (mkdir, touch, rm), reading (cat, less), copying/moving (cp, mv). That's the 20% of commands you'll use 80% of the time.
Mini-challenge (no docs allowed): create a ~/playground folder and enter it; create 3 empty files a.txt, b.txt, c.txt; copy a.txt to a-copie.txt; rename b.txt to important.txt; delete c.txt; list the contents with details (size, dates, permissions).
⚠️ rm deletes permanently — there is no trash bin on the CLI. Here we only touch empty files created inside ~/playground; that's what this sandbox is for.
Solution (only look after you've tried):
mkdir -p ~/playground && cd ~/playground
touch a.txt b.txt c.txt
cp a.txt a-copie.txt
mv b.txt important.txt
rm c.txt # suppression définitive / permanent deletion
ls -la✅ Check: you complete all 6 actions in under 2 minutes, without Google. ls -la shows a.txt, a-copie.txt, important.txt — and no more c.txt. Tier cleared.
step-02
Goal. Tier 2 — Navigate. Read the repo's "Everyday use" section, focusing on four topics: history (↑, !!, !$, Ctrl-R), globbing (*, ?, [abc], {a,b,c}), keyboard shortcuts (Ctrl-A, Ctrl-E, Ctrl-W, Ctrl-U), and redirections (>, >>, 2>, 2>&1, |).
🤔 Why these 4 topics first?
- History makes you type 10× less.
- Globbing lets you treat 100 files as 1.
- Shortcuts let you edit your line without mouse or arrow keys.
- Redirections open up the Unix philosophy: composing small tools.
Mini-challenge: list every .log file in /var/log/ while redirecting permission errors to /dev/null; show the last 5 lines of your history; create 10 files test1.txt through test10.txt in a single command; find an earlier command with Ctrl-R.
Solution:
ls /var/log/*.log 2>/dev/null
tail -n 5 ~/.bash_history
cd ~/playground && touch test{1..10}.txt
# Ctrl-R puis tape un fragment / then type a fragment, Enter pour exécuter / to run✅ Check: the ls shows no "Permission denied" error (they go to /dev/null), ls test*.txt shows exactly 10 files, and Ctrl-R finds an old command of yours in 3 keystrokes.
step-03
Goal. Tier 3 — Understand (text + data). Read "Processing files and data" then "One-liners".
🤔 Why does this tier change your life? Most ops/dev work is digging through logs, config files, JSON, CSV. Without grep/sed/awk/jq, you do it by hand = you die. With these tools, what would take 2 hours takes 30 seconds.
Focus on: grep (search + basic regex), sed (just s/old/new/g and -i), awk (just awk '{print $N}' and simple filters), the "top N" pattern sort | uniq -c | sort -rn, and jq (parsing JSON).
Mini-challenge: how many lines of /etc/passwd contain bash? Print only the username (1st column) of each line. What are the 5 most-used shells on your system (last column)? Bonus: fetch Torvalds' GitHub profile with curl and extract the public_repos field with jq.
Solution:
grep -c bash /etc/passwd
awk -F: '{print $1}' /etc/passwd
awk -F: '{print $NF}' /etc/passwd | sort | uniq -c | sort -rn | head -5
curl -s https://api.github.com/users/torvalds | jq .public_repos✅ Check: every one-liner returns a plausible result (numbers, usernames, a shell ranking), and above all: you can explain each segment of the sort | uniq -c | sort -rn | head -5 pipeline out loud. If jq is missing: sudo apt install jq (Debian/Ubuntu).
step-04
Goal. Tier 4 — Investigate. Read "System debugging".
🤔 Why is this essential for what comes next? Every self-hosting guide on this platform will have you install services that sometimes break. Knowing how to investigate (ps, top/htop, df, du, lsof, journalctl, dmesg) is the difference between "it doesn't work, I give up" and "OK, I can see what's going on".
Mini-challenge: which process eats the most RAM on your machine? What percentage of your / disk is used? What's the biggest folder in your $HOME? Which port does the SSH service use?
Solution:
ps aux --sort=-%mem | head -5
df -h /
du -sh ~/*/ 2>/dev/null | sort -rh | head -1
sudo ss -tlnp | grep sshd # ou / or: grep -i port /etc/ssh/sshd_config✅ Check: you answer all 4 questions with concrete values (a process name, a percentage, a folder, a port number — 22 by default). Bonus: you understand why 2>/dev/null silences the noise from unreadable folders.
§ 06 Known pitfalls
1. The "fear of the unknown" that makes you copy-paste without understanding. The worst possible habit. Before running a command found on Stack Overflow, especially with sudo, read every flag. man <command> is your friend. So is tldr <command> (shorter).
2. chmod 777 "so it works". Beginner anti-pattern #1. Giving everyone every right solves 0 problems and creates 10. Learn the u/g/o + rwx triad. It's a 10-minute investment.
3. A misplaced rm -rf. ⚠️ Destructive, irreversible command. Always type pwd before an rm -rf, and beware of empty variables: in 2015, Steam for Linux ran rm -rf "$STEAMROOT/"* with STEAMROOT empty → users' entire home directories wiped.
4. Mixing up > and >>. > overwrites, >> appends. Running > on an existing config file empties it. Always double-check first.
5. Pasting multi-line text containing newlines. The shell treats each newline as an "Enter". If you copy 5 lines from a website and one hides an rm -rf /, it runs before you can panic. Pro habit: paste into an editor first, read, then run line by line.
§ 07 You're done when…
You know it works when…
- You open a terminal without thinking, the way you open a browser.
- You use
Ctrl-Rmore often than the up arrow. - You know what
cat file.txt | grep error | wc -ldoes just by reading it. - You read
man <cmd>instead of Googling every doubt. - You have a customized
~/.bashrc(or.zshrc) with 2-3 aliases of your own.
If all 5 are ticked, you're ready for Docker, Git, advanced SSH, and everything else.
§ 08 What's next?
Four natural extensions, from most urgent to most comfortable:
- Git fundamentals — versioning, branches, collaboration: the official follow-up to this guide.
- SSH & remote servers — connecting, copying (
scp,rsync), working remotely. - Bash scripting — writing your first useful scripts (backup, alerting, batch jobs).
tmux— persistent terminal sessions, indispensable once you work over SSH.
§ 09 Cheatsheet
Quick reference of the path's key commands and shortcuts.
# Bouger & voir / Move & see
pwd # où suis-je / where am I
cd <dir> ; cd - ; cd # aller / revenir / home
ls -la # tout, avec détails / everything, detailed
# Créer, copier, supprimer / Create, copy, delete
mkdir -p a/b/c # dossiers imbriqués / nested dirs
cp src dst ; mv src dst # copier / déplacer-renommer
rm fichier # ⚠️ définitif / permanent — pwd d'abord / pwd first
# Lire / Read
cat f ; less f ; head -n 20 f ; tail -f f
# Historique & édition / History & editing
Ctrl-R # recherche dans l'historique / history search
!! ; !$ # dernière commande / dernier argument — last cmd / last arg
Ctrl-A / Ctrl-E / Ctrl-W / Ctrl-U
# Redirections & pipes
cmd > f # écrase / overwrite
cmd >> f # ajoute / append
cmd 2> f ; cmd 2>&1 # stderr
cmd1 | cmd2 # pipe
# Texte / Text
grep -rn "motif" . # chercher / search
sed 's/old/new/g' f # remplacer / replace
awk -F: '{print $1}' f # colonne / column
sort | uniq -c | sort -rn | head -5 # top N
# Investiguer / Investigate
ps aux --sort=-%mem | head # RAM
df -h ; du -sh */ # disque / disk
ss -tlnp # ports ouverts / open ports
echo $? # code de sortie / exit code§ 10 Resources
- jlevy/the-art-of-command-line — this path's reference repo (also available in several languages).
- MIT — The Missing Semester — free university course, an excellent complement.
- tldr pages — short, practical versions of
manpages. - explainshell.com — paste a complex command, every piece gets explained.
§ 11 Troubleshooting
"Permission denied" on almost everything. You're probably touching a file you don't own. Run ls -la to see the permissions. Either the file is yours (fix the perms with chmod), or it's a system file (use sudo — understanding what you're doing).
"Command not found" on a "standard" command. Either the package isn't installed (sudo apt install <package> on Debian/Ubuntu), or it isn't in your $PATH. Check with echo $PATH.
You're stuck in vim and can't get out. A classic. Press Esc, then type :q! then Enter. To avoid it entirely, set nano as your default editor: export EDITOR=nano in your .bashrc.
Your terminal seems frozen, nothing responds. You probably hit Ctrl-S (display freeze, an old flow-control mechanism). Hit Ctrl-Q to unfreeze. If you're stuck in less or man, the q key gets you out.