Linux

Linux Commands Cheat Sheet

The everyday Linux command set on one page: navigation, files, permissions, processes, networking, disk, and the pipes that glue them together.

Linuxcommand lineterminalcheat sheetreference

Orientation

CommandWhat it does
pwdPrint working directory — where am I?
ls -laList everything here, long form, including hidden files
cd path / cd ~ / cd -Change directory / go home / go back to previous
man cmd or cmd --helpThe manual / quick help for any command
which cmdWhere does this command live?
historyWhat have I typed lately?

Files and directories

CommandWhat it does
mkdir -p a/b/cCreate nested directories in one go
touch fileCreate an empty file (or update its timestamp)
cp src dest / cp -r dir destCopy a file / a directory tree
mv old newMove — which is also how you rename
rm file / rm -rf dirDelete a file / a whole tree — permanent, no trash can
cat filePrint a file's contents
less filePage through a long file (q to quit, / to search)
head -20 file / tail -20 fileFirst / last 20 lines
tail -f app.logFollow a log as it grows — the debugging classic
ln -s target linknameSymbolic link

Finding things

CommandWhat it does
find . -name "*.md"Find files by name, recursively
find . -type d -name "node_modules"Find directories by name
grep -r "text" .Search file contents recursively
grep -ri "text" .Same, case-insensitive
grep -l "text" *.logJust list the files that match
du -sh *Size of everything here, human-readable
df -hDisk space across mounted filesystems

Permissions

Permission string: -rwxr-xr-- = type, then owner / group / other triads of read, write, execute.

CommandWhat it does
chmod +x script.shMake executable
chmod 644 fileOwner read/write; everyone else read (normal file)
chmod 755 scriptOwner all; others read + execute (normal script/directory)
chmod 600 secretsOwner read/write; nobody else anything (keys, credentials)
chown user:group fileChange owner (usually needs sudo)
sudo cmdRun one command with elevated rights — deliberately, not reflexively

Numeric key: r=4, w=2, x=1, summed per triad — so 754 = rwx r-x r--.

Processes

CommandWhat it does
ps auxEvery running process
ps aux | grep nodeFind a specific one
top (or htop if installed)Live process/CPU/memory view
kill PIDAsk a process to stop
kill -9 PIDForce it to stop (last resort)
cmd &Run in the background
jobs / fgList background jobs / bring one forward

System, services, and power

CommandWhat it does
uptimeHow long it has been up, and load average
sudo rebootRestart now (sudo systemctl reboot is the same thing)
sudo shutdown -r +5 "msg"Restart in 5 minutes, warning logged-in users
sudo shutdown -h now / sudo poweroffPower off now
sudo shutdown -cCancel a scheduled shutdown
whoWho else is logged in — check before rebooting a shared box
systemctl status svcIs a service running, and why did it stop?
sudo systemctl restart svcRestart one service instead of the whole machine
sudo systemctl enable --now svcStart it and have it start on boot
journalctl -u svc -n 50Last 50 log lines for a service
journalctl -b -p errErrors from this boot only
ls /var/run/reboot-requiredDebian/Ubuntu: does a pending update need a reboot?

Networking

CommandWhat it does
ping hostIs it reachable?
curl -I https://example.comFetch just the HTTP headers
curl -O url / wget urlDownload a file
ssh user@hostOpen a shell on another machine
scp file user@host:/pathCopy a file over SSH
ip aThis machine's network interfaces and addresses
ss -tlnpWhat's listening on which port (run with sudo to see process names)

Pipes and redirection — the glue

PatternWhat it does
a | bOutput of a becomes input of b
cmd > fileWrite output to file (replace)
cmd >> fileAppend output to file
cmd 2> errors.txtCapture error output separately
cmd1 && cmd2Run cmd2 only if cmd1 succeeded
sort | uniq -c | sort -rnCount occurrences, most frequent first
wc -lCount lines

Worked example — the five most common words in a file:

tr ' ' '\n' < essay.txt | sort | uniq -c | sort -rn | head -5

Package managers by family

FamilyUpdate indexInstallRemove
Debian / Ubuntusudo apt updatesudo apt install pkgsudo apt remove pkg
Fedora / RHELsudo dnf check-updatesudo dnf install pkgsudo dnf remove pkg
Archsudo pacman -Sysudo pacman -S pkgsudo pacman -R pkg
Alpine (containers)apk updateapk add pkgapk del pkg

The safety rules

  • pwd before anything destructive — know where you're standing.
  • Preview any wildcard delete: run ls with the same pattern before rm.
  • rm -rf is permanent. There is no undo, no trash.
  • Quote paths with spaces: "my file.txt".
  • Read the error before reaching for sudo.

Go deeper: every command here is taught hands-on in Linux Command Line Essentials. Save this page — it's built to be the tab you keep open.