Cheat Sheet

Linux/Bash Commands Cheat Sheet — Daily Terminal Reference

Practical Linux/bash command reference for daily terminal use: file ops, text processing, processes, networking, permissions. Free, dense, with real examples.

A practical Linux command reference — what you actually run from a terminal. Works on most Linuxes and macOS (BSD sed/find have minor quirks; flagged where it matters).

Files & directories

CommandWhat it does
pwdPrint working directory
ls -lahList with sizes, permissions, hidden files
cd ~Go home
cd -Go to previous directory
mkdir -p a/b/cCreate nested directories
cp file dest / cp -r dir destCopy file / directory
mv old newMove or rename
rm fileDelete file
rm -rf dirDelete directory recursively (DESTRUCTIVE)
ln -s target linkSymbolic link
touch fileCreate empty file / update timestamp
du -sh *Size of each item in current dir, human-readable
du -sh * | sort -hSorted by size
df -hDisk space free per filesystem
tree -L 2Visual directory tree, 2 levels deep

Search & find

CommandWhat it does
find . -name "*.log"Files matching name
find . -type d -name node_modulesDirectories named node_modules
find . -mtime -7Modified in last 7 days
find . -size +100MLarger than 100 MB
find . -name "*.tmp" -deleteFind and delete
find . -name "*.js" -exec grep "TODO" {} +Run command on each match
grep "pattern" fileLines matching pattern
grep -r "pattern" .Recursive grep
grep -rni "todo" --include="*.js"Recursive, case-insensitive, line numbers, only .js
rg "pattern"ripgrep — much faster than grep
locate filenameFind file by name (uses index)
which pythonPath to executable in $PATH

Viewing files

CommandWhat it does
cat filePrint whole file
less filePage through file (q to quit, / to search)
head -20 fileFirst 20 lines
tail -20 fileLast 20 lines
tail -f fileFollow new lines as they arrive (logs)
wc -l fileCount lines

Text processing

CommandWhat it does
sort fileSort lines
sort -u fileSort + remove duplicates
sort -hrSort by human-readable numbers, reverse
uniq fileRemove consecutive duplicates (sort first!)
uniq -cCount occurrences
cut -d',' -f1,3 file.csvColumns 1 and 3 by comma
awk '{print $1}'First whitespace-separated field
awk -F',' '{sum += $2} END {print sum}'Sum column 2
sed 's/old/new/g' fileSubstitute (print to stdout)
sed -i 's/old/new/g' fileSubstitute in-place
tr 'a-z' 'A-Z'Translate (e.g., upper case)
jq '.users[].email' data.jsonExtract from JSON (separate install)

Pipes & redirection

cmd1 | cmd2          # pipe stdout of cmd1 to stdin of cmd2
cmd > file           # write stdout to file (overwrite)
cmd >> file          # append stdout to file
cmd 2> errors.log    # redirect stderr
cmd > out 2> err     # split stdout and stderr
cmd &> combined.log  # both to one file
cmd < input.txt      # read stdin from file
echo "hi" | tee file # write to file AND stdout

Permissions

CommandWhat it does
chmod 644 filerw for owner, r for group/others
chmod 755 filerwx owner, rx group/others (typical executable)
chmod +x script.shAdd execute bit
chmod -R 755 dirRecursive
chown user:group fileChange owner + group
sudo commandRun as root (or another user with -u)

Permission notation: 4=read, 2=write, 1=execute. Add to combine. 755 = 7 (4+2+1) for owner, 5 (4+1) for group + others.

Processes

CommandWhat it does
ps auxAll running processes
ps aux | grep nginxFilter for a process
top / htopLive process viewer (htop is friendlier)
kill <pid>Send SIGTERM (graceful)
kill -9 <pid>SIGKILL (force, no cleanup)
killall nginxKill all processes by name
cmd &Run in background
nohup cmd &Background + survive logout
jobsList jobs in current shell
fg %1Bring job 1 to foreground
bg %1Resume job 1 in background

Networking

CommandWhat it does
curl -I urlHEAD request — show headers
curl -L urlFollow redirects
curl -X POST -H "Content-Type: application/json" -d '{"a":1}' urlPOST JSON
wget urlDownload file
ping hostICMP echo
dig example.comDNS lookup
nslookup example.comDNS lookup (older alternative)
ss -tulpnOpen TCP/UDP ports + processes (modern)
netstat -tulpnSame (legacy)
traceroute hostPath to a host
ip aNetwork interfaces

Compression / archives

CommandWhat it does
tar -czvf out.tar.gz dir/Create gzipped tar
tar -xzvf in.tar.gzExtract gzipped tar
tar -xzvf file.tar.gz -C /target/Extract to specific directory
zip -r out.zip dir/Create zip
unzip file.zipExtract zip
gzip file / gunzip file.gzSingle-file compress / decompress

Variables & scripting

# Variable
NAME="Alice"
echo "Hello $NAME"

# Command substitution
TODAY=$(date +%Y-%m-%d)
echo "Today is $TODAY"

# Conditionals
if [ -f "file.txt" ]; then echo "exists"; fi
if [[ "$1" == "deploy" ]]; then ./deploy.sh; fi

# Loops
for f in *.log; do gzip "$f"; done
for i in {1..5}; do echo $i; done

# Functions
greet() { echo "Hello, $1"; }
greet Alice

# Exit on first error (recommended at top of scripts)
set -euo pipefail

SSH

CommandWhat it does
ssh user@hostConnect
ssh -p 2222 user@hostCustom port
ssh-keygen -t ed25519Generate keypair
ssh-copy-id user@hostInstall your public key on server
scp file user@host:/path/Copy file to server
rsync -avz dir/ user@host:/path/Smart sync (resumable, only deltas)
ssh -L 8080:localhost:80 user@hostTunnel local 8080 to host's 80

Related tools

Test regex patterns before sed/grep: regex tester. Compute or verify file SHA hashes: hash generator. Decode Base64-encoded payloads (e.g., from environment files): Base64 encoder/decoder.

Featured Tools

Try these free tools directly in your browser — no sign-up required.

linux cheat sheet bash cheat sheet linux commands terminal commands unix reference

Explore 300+ Free Tools

Utilko has tools for developers, writers, designers, students, and everyday users — all free, all browser-based.