Bash Cheat Sheet: 40 Commands & One-Liners You'll Use Daily

If you spend any time in a terminal, a handful of Bash commands will carry you through 90% of your work. The trick is knowing which ones — and how to chain them. This cheat sheet gives you 40 commands and one-liners you'll actually reach for daily, with short, copy-pasteable examples. It's also a great companion if you want to learn Bash free without wading through a 500-page manual: bookmark this, practice the snippets, and the muscle memory will follow.
We've grouped everything into six practical buckets: navigation, files, viewing and searching text, processes and system, networking, and scripting glue. Let's go.
Navigation & the basics
These are the commands your fingers should type without thinking.
pwd # print working directory
ls -lah # list files: long, all, human-readable sizes
cd - # jump back to the previous directory
pushd /var/log # cd to a dir AND remember where you were
popd # ...then jump back
history | tail -20 # what did I just run?
!! # re-run the last command (try: sudo !!)
Ctrl + R # reverse-search your command history
That Ctrl + R shortcut alone saves more keystrokes than anything else on this list. Start typing part of an old command and Bash finds it.
Working with files & directories
cp -r src/ backup/ # copy a directory recursively
mv old.txt new.txt # rename or move
rm -rf node_modules # delete recursively (careful!)
mkdir -p a/b/c # create nested directories at once
touch file.txt # create an empty file / update timestamp
ln -s /opt/app/bin app # create a symbolic link
chmod +x deploy.sh # make a script executable
du -sh * # size of each item in the current dir
df -h # free disk space, human-readable
find . -name "*.log" -mtime +7 -delete # delete logs older than 7 days
That last find one-liner is the kind of thing you'll paste into a cron job and forget about. Swap -delete for -print first to preview what it matches.
Viewing & searching text
Text wrangling is where Bash really earns its keep.
cat file.txt # dump a file
less +F app.log # page through a file; +F follows like tail -f
head -n 50 data.csv # first 50 lines
tail -f /var/log/syslog # follow a log live
grep -rn "TODO" src/ # recursive search with line numbers
grep -i "error" app.log | wc -l # count matching lines, case-insensitive
awk -F',' '{print $2}' data.csv # print the 2nd CSV column
sed -n '10,20p' file.txt # print lines 10–20
sed -i 's/foo/bar/g' *.txt # find & replace in place across files
sort access.log | uniq -c | sort -nr | head # top values by frequency
cut -d':' -f1 /etc/passwd # first field of each line
diff -u old.txt new.txt # unified diff between two files
That sort | uniq -c | sort -nr pipeline is a classic — point it at a log file and instantly see your top error messages, IPs, or URLs. If regular expressions trip you up here, our guide to 5 regex patterns every developer should know pairs perfectly with grep and sed.
Processes & system
ps aux | grep node # find a running process
top # live process monitor (or 'htop' if installed)
kill -9 12345 # force-kill a process by PID
pkill -f "webpack" # kill processes matching a pattern
jobs # background jobs in this shell
bg / fg # send a job to background / foreground
nohup ./long-task.sh & # run a task that survives logout
lsof -i :3000 # what's using port 3000?
watch -n 2 'free -m' # re-run a command every 2 seconds
When a dev server won't start because "the port is in use," lsof -i :3000 followed by kill is the two-step fix you'll use constantly.
Networking & transfers
curl -sS https://api.example.com/health # quick HTTP check
curl -O https://example.com/file.zip # download a file
wget -c https://example.com/big.iso # resumable download
ssh user@server -p 2222 # connect to a remote box
scp file.txt user@server:/tmp/ # copy a file over SSH
rsync -avz ./site/ user@server:/var/www/ # fast, incremental sync
ping -c 4 google.com # 4 pings and stop
rsync -avz is the deploy command for a thousand small projects — it only transfers what changed.
Scripting glue you'll reuse
Even if you're not writing big programs, these small patterns show up in nearly every script:
for f in *.png; do echo "$f"; done # loop over files
if [ -f config.yml ]; then echo found; fi # test for a file
cmd1 && cmd2 # run cmd2 only if cmd1 succeeds
cmd1 || echo "failed" # run fallback on failure
export API_KEY="abc123" # set an environment variable
NAME=${1:-default} # use $1 or a default value
VAR=$(date +%F) # capture command output
Keep set -euo pipefail at the top of every script you write — it makes Bash fail loudly instead of silently limping along after an error.
How to actually retain this
Reading a cheat sheet is easy; remembering it is the hard part. The fix is repetition in a real shell. A few suggestions:
- Pick three commands a day and force yourself to use them instead of your usual habit (e.g.,
Ctrl + Rinstead of arrow-key spamming). - Build one tiny script a week — a backup, a log summarizer, a project bootstrapper.
- Follow a structured path. Our 30-day roadmap to learn Bash for free breaks the whole thing into bite-sized daily tasks, and the hands-on best free Bash scripting course lets you practice in the browser.
If you also work with databases, keep our SQL cheat sheet next to this one — the two cover most of the command-line work a developer does in a day.
Wrapping up
These 40 commands aren't an exhaustive reference — they're the working set. Master navigation, file operations, the grep/awk/sed trio, process control, and a little scripting glue, and you'll handle the vast majority of terminal tasks without looking anything up. The best part is that you can learn Bash free entirely from your own machine: every command above runs on Linux, macOS, and WSL right now.
Ready to go deeper? Start the best free Bash scripting course on FreeAcademy.ai and turn these one-liners into scripts you'll rely on for years.

