Terminal cheat sheet

The commands beginners reach for every day, on one page: moving around, files, grep, pipes, permissions, Git and the Git undo commands, plus what to check before you approve an AI agent's command. Free to read, print or save as a PDF.

Where am I?

pwd
print the folder you're in
ls · ls -la
list files · all, with details
cd projects
go into a folder
cd .. · cd ~ · cd -
up one · home · back
tree
draw folders as a tree

Files & folders

mkdir -p a/b/c
make folders, parents too
touch notes.txt
create an empty file
cp a.txt b.txt · cp -r
copy · a whole folder
mv old.txt new.txt
rename or move
rm file · rm -r folder
delete (no bin, no undo!)
ls *.log then rm *.log
preview a wildcard first

Read & search

cat · less
print a file · page through it (q quits)
head -n 5 · tail -n 5
first · last lines
grep -in error app.log
matching lines: any case, numbered
grep -rn TODO .
search every file below here
find . -name "*.md"
find files by name
wc -l file
count lines

Pipes & redirects

cmd > out.txt · >>
save output (replace) · append
cmd 2> err.txt · &> all
save errors · both streams
cmd1 | cmd2
feed output into the next command
sort | uniq -c | sort -rn
count and rank lines
a && b · a || b
b only if a worked · failed

Permissions

ls -l
-rwxr-xr-x: type, owner, group, others
chmod 644 file
you edit, everyone reads
chmod 755 script.sh
you edit, everyone runs
chmod 600 .env
only you (secrets, keys)
chmod +x script.sh
make it runnable

Git: save work

git status · git status -s
what changed
git add file · git add .
stage for the next commit
git diff · git diff --staged
unstaged · staged changes
git commit -m "message"
save a snapshot
git log --oneline
history, one line each
git switch -c name
new branch and switch to it

Git: undo

git restore --staged file
unstage (keeps your edit)
git restore file
discard edits to a file ⚠
git reset --soft HEAD~1
undo last commit, keep changes
git commit --amend -m "…"
fix the last message (unpushed)
git revert --no-edit HEAD
undo a pushed commit safely
git reflog
find lost commits and branches

Before you approve an AI agent's command

rm -rf $VAR/…
empty $VAR = deletes from /
curl … | sh
runs code you haven't read
chmod 777
anyone can change it
git push --force
can erase teammates' work
git reset --hard
wipes uncommitted work

Practise this in 5 minutes

A cheat sheet reminds you; practice makes it stick. Lesson 1 has you typing real commands in a safe terminal, with instant feedback.

Start the free lessons

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.