Cheat sheetDev

Terminal basics

The terminal commands you'll actually use daily — navigation, files, search, pipes, and process control in one page.

Last updated

Moving around

CommandWhat it does
pwdPrints where you actually are — the answer once relative paths stop making sense.
ls -laLists hidden dotfiles and permissions too — plain ls hides configs like .env and .git.
ls -lhSame listing, but sizes shown as 4.2K instead of 4200 — for hunting a huge file.
cd -Jumps back to wherever you just were — the undo button for cd.
cd ~Home, no matter how deep you've wandered.
find . -type dLists every folder under here — the map before you go searching inside them.

Files

CommandWhat it does
cp file.txt backup.txtDuplicates a file — the original stays untouched.
cp -r src/ dest/Copies a whole folder tree — plain cp refuses directories outright.
mv old.txt new.txtRenames a file — same command whether you're moving it or just renaming it.
rm file.txtDeletes for good — no trash can to fish it back out of.
rm -r folder/Deletes a folder and everything inside it — double-check the path first.
mkdir -p a/b/cCreates nested folders in one shot, even if a and b don't exist yet.
touch file.txtCreates an empty file, or just updates its timestamp if it already exists.
cat file.txtDumps the whole file to the screen — fine for short files, useless for long ones.
less file.txtOpens a file you can scroll and search without it flooding your terminal.
head -n 20 file.txtFirst 20 lines — the fast way to check what a file even is.
tail -f log.txtFollows a file as it grows — the standard way to watch a log live.

Searching

CommandWhat it does
grep -r "TODO" .Recursively searches file contents — finds a string no matter how deep it's buried.
grep -ri "error" log.txtCase-insensitive search — catches Error, ERROR, and error alike.
find . -name "*.env"Finds files by name pattern anywhere below here, not just the current folder.
which nodePrints the exact path of the executable that would run — for chasing down 'command not found' or the wrong version.
historyEvery command you've typed this session, numbered — !42 reruns line 42.
history | grep dockerSearches your command history instead of scrolling back through it.

Pipes & redirection

CommandWhat it does
cmd1 | cmd2Feeds the output of one command straight into the next — the glue of the shell.
cmd > file.txtWrites output to a file, overwriting whatever was already there.
cmd >> file.txtAppends output to a file instead of overwriting it.
cmd > out.log 2>&1Sends both normal output and errors into the same file.
find . -name "*.tmp" | xargs rmTurns a list of results into arguments for another command.
cmd | tee file.txtShows output on screen AND saves it to a file at the same time.

Processes & help

CommandWhat it does
ps auxLists every running process with its PID — what you need before you can kill anything.
kill 1234Asks a process to shut down gracefully, by its PID.
kill -9 1234Forces a stuck process to die immediately — the last resort, not the first.
topA live, updating view of what's eating your CPU and memory right now.
Ctrl+CStops whatever's running in the foreground — the universal 'get me out of this'.
Ctrl+ZPauses the foreground job and hands the prompt back — the process is frozen, not stopped.
fgResumes whatever you just paused with Ctrl+Z, back in the foreground.
man lsOpens the full manual for a command, with every flag it supports.
ls --helpA quick flag summary without leaving your prompt — faster than man for a refresher.

Worth remembering

  • Tab-completion isn't optional — it saves you from typos in paths and surfaces files you forgot existed.
  • rm has no undo — for anything that matters, cp -r it somewhere safe first, or reach for a trash-cli instead.

Related in Cheat sheets