27 Sep 2026 · 8 min readCoding

The Shell: The Twenty Commands That Cover Almost Everything

The shell is the most useful thing on your machine, and the least taught. You do not need to memorise it — you need about twenty commands and three ideas: how programs chain together, how output goes somewhere other than the screen, and how to write a small script safely. This guide covers exactly that.

Three ideas that make the rest obvious

  • Everything is a program, and a program reads input and writes output. The shell just connects them.
  • Pipes (`|`) send one command's output to the next as input. This is why small tools compose into something powerful.
  • Redirection (`>`, `>>`, `<`) changes where input comes from and where output goes.
bash
cat access.log | grep ' 500 ' | sort | uniq -c | sort -rn | head

That one line counts the most common server errors, sorted, top ten. None of those tools knows what it is part of. That is the whole idea.

The ones worth memorising

  • ls, cd, pwd — move around.
  • cp, mv, rm — copy, move, delete. Learn the flags before you use rm on anything large.
  • cat, head, tail, less — look at things. `tail -f` on a log file is the one you will use daily.
  • grep — search inside files. The most used command on any machine.
  • find — search for files by name, size or date.
  • chmod — permissions. 644 for files and 755 for scripts is a reasonable default.
  • ps, kill, top — see what is running and stop it.
  • curl — make HTTP requests. This is how you test an API.
  • ssh, scp — remote machines.
  • tar, zip — archive and extract.
⚠️ Note: There is no undo for `rm`. Before running any recursive delete, print the path first and read it. This is the one genuinely irreversible command in daily use.

Writing small scripts safely

  • Start with `#!/usr/bin/env bash` and a shebang, then make it executable with chmod +x.
  • Add `set -euo pipefail` at the top. It stops the script on the first error instead of ploughing on and corrupting something.
  • Quote every variable: "$var" not $var. This alone prevents a large class of nasty bugs.
  • Run it with bash -x for a trace of every command, which is the fastest way to see where it went wrong.
  • Add an echo of what it is about to do before anything destructive.
bash
#!/usr/bin/env bash
set -euo pipefail

target="${1:?usage: clean.sh <dir>}"
echo "about to remove old logs in $target"
find "$target" -name '*.log' -mtime +30 -print -delete

Tools for the same job in a browser

Explore the Full SlashAI Library

Every prompt in our guides is part of our offline-ready vault of verified commands and instant browser tools. Free forever, no account required.

Browse All Commands