Linux Commands Cheat Sheet

Which Linux command to use for which job: shell mechanics, files and text, processes, disks, network, users and scheduling, with the form you will actually type.

What do you need to do

Find a file or some text in files
find, grep
Watch a log as it happens
tail -f, journalctl -f
Find what is eating the disk
df -h, then du -sh *
Find what is eating the CPU
top
See who is listening on a port
ss -tulpn
Edit a config file
nano, or vi when nano is absent
This sheet answers “which one”, not “every flag”. Each line names the tool for a job and shows the form you will actually type. When you need the full set of options for one of them, the per-tool sheets linked at the bottom go deeper.

How commands join together

GoalSyntax
Feed one command into anotherps aux | grep nginx
Write output to a file, replacing itdf -h > /tmp/disk.txt
Append instead of replacingdate >> /tmp/run.log
Capture errors as well./job.sh > out.log 2>&1
Throw output awayfind / -name x 2>/dev/null
Run the second only if the first workedmake && ./deploy.sh
Run the second only if the first failedping -c1 host || echo down
Use a command’s output as a valueecho "lines: $(wc -l < file)"
Everything matching a patternrm /tmp/*.log
Turn a list into argumentscat hosts | xargs -I{} ping -c1 {}
Page through long outputjournalctl | less
Repeat a command every two secondswatch df -h
At the promptKeys
Complete a nameTab, twice to list the options
Previous commandsUp arrow, or history
Search what you typed beforeCtrl+R, then part of the command
Repeat the last command as rootsudo !!
Stop a running commandCtrl+C
Clear the screenCtrl+L
Quit a pager such as less or manq
Quotes matter more than in cmd. The shell expands *, $ and spaces before the command ever sees them, so a path with a space needs quotes. Single quotes pass text through untouched, double quotes still expand variables.

Finding out what a command does

QuestionCommand
Full manualman rsync, then /pattern to search and q to leave
Quick option listrsync --help
What is this thing at allwhatis rsync
Which commands relate to a topicapropos partition
Where does this command livewhich rsync, or type rsync
Is it a file, a builtin or an aliastype -a cd
Which package provides itrpm -qf $(which ss) or dpkg -S $(which ss)

Moving around and finding things

TaskCommand
Where am Ipwd
List, with details and hidden filesls -lah
Newest files lastls -lahtr
Go somewhere, and backcd /etc, then cd -
Find files by namefind /var -name "*.log"
Find files changed in the last dayfind /etc -mtime -1
Find files over 100 MBfind / -size +100M 2>/dev/null
Find and act on each resultfind /tmp -name "*.tmp" -delete
What kind of file is thisfile /usr/bin/ssh
Size, owner, timestampsstat report.csv
Tree view, if installedtree -L 2

Reading files

TaskCommand
Show a short filecat /etc/hosts
Page through a long oneless /var/log/syslog
First or last lineshead -20 file, tail -50 file
Follow a log livetail -f /var/log/nginx/error.log
Count lines, words, byteswc -l file
Compare two filesdiff -u old.conf new.conf
Checksumsha256sum image.iso
Read a compressed log without unpackingzcat old.log.gz | less
Pretty-print JSONjq . data.json
Inside less. /text searches forward and n repeats it, G jumps to the end, g to the start, q quits. less +F behaves like tail -f but lets you press Ctrl+C and scroll back.

Working with text

TaskCommand
Find a string in a filegrep "error" /var/log/syslog
Ignore case, show line numbersgrep -in "error" file
Search a whole treegrep -rn "TimeoutSec" /etc/systemd
Show context around the hitgrep -C3 "failed" file
Everything except a patterngrep -v "debug" file
Count matchesgrep -c "error" file
Replace text on screensed 's/old/new/g' file
Replace in the file itselfsed -i 's/old/new/g' file
Print one columnawk '{print $3}' file
Sum a columnawk '{s+=$2} END {print s}' file
Split on a delimitercut -d: -f1 /etc/passwd
Sort, then count duplicatessort file | uniq -c | sort -rn
Sort by the second column, numericallysort -k2 -n file
sed -i edits in place with no undo. Run it without -i first and read the result, or keep a copy with sed -i.bak, which writes file.bak beside the original.

Files, archives and transfer

TaskCommand
Copy, and copy a foldercp a b, cp -r dir/ dest/
Move or renamemv old new
Delete, and delete a folderrm file, rm -r dir
Create a folder pathmkdir -p /opt/app/logs
Create an empty filetouch /tmp/marker
Symbolic linkln -s /opt/app/current /opt/app/live
Copy a tree efficientlyrsync -avh src/ dest/
Copy to another machinersync -avh dir/ user@host:/backup/
Pack a foldertar -czf app.tar.gz /opt/app
Unpack ittar -xzf app.tar.gz -C /tmp
Look inside without unpackingtar -tzf app.tar.gz | head
Zip, for someone on Windowszip -r app.zip /opt/app
Download a filecurl -O https://host/file, or wget
Remember tar by its three letters. -c create, -x extract, -t list. Add -z for .gz and -f for the file name, which is why czf and xzf cover almost everything.

Processes and jobs

TaskCommand
Live view of load and processestop, or htop if installed
Every process, one snapshotps aux
Find a process by namepgrep -a nginx
Top consumers of CPUps aux --sort=-%cpu | head
Top consumers of memoryps aux --sort=-%mem | head
Ask a process to stopkill 1234
Make it stopkill -9 1234
By name instead of PIDpkill nginx
What has this file or port openlsof /var/log/app.log, lsof -i :443
Run something that survives logoutnohup ./job.sh &
Keep a session alive across disconnectstmux, detach with Ctrl+B then D
Come back to ittmux attach
Background the current commandCtrl+Z, then bg, list with jobs
kill -9 is the last resort, not the first. Plain kill asks the process to shut down and flush its work. -9 removes it instantly and whatever it was writing stays half written. For anything managed by systemd, systemctl restart is better than either.

System, disks and space

TaskCommand
Distribution and versioncat /etc/os-release
Kernel, hostname, virtualisationuname -a, hostnamectl
Uptime and load averageuptime
Memory, in human unitsfree -h
CPU model and core countlscpu
Free space per filesystemdf -hT
What is big in this folderdu -sh * | sort -h
Disks, partitions and mount pointslsblk -f
What is mounted, readablyfindmnt
Hardware and driver messagesdmesg -T | tail -50
Service state and logssystemctl status name, journalctl -u name
Reboot or power offreboot, poweroff
Disk full but du finds nothing? Either a deleted file is still held open, which lsof | grep deleted reveals, or you have run out of inodes rather than bytes, which df -i shows.

Network

TaskCommand
Addresses, one line eachip -br a
Routing tableip r
Listening ports and their processesss -tulpn
Is the host upping -c4 10.0.0.1
Is the port opennc -zv 10.0.0.50 443
Resolve a namedig example.com +short
Where does the path breaktraceroute -n 8.8.8.8
Test an HTTP endpointcurl -I https://example.com
Connect to another serverssh user@host
Watch packetstcpdump -i any -nn port 443

Users, access and scheduling

TaskCommand
Who am I, and in which groupsid
Who is logged inwho, or w for what they are doing
Recent loginslast -10
What may I run as rootsudo -l
Become root for a sessionsudo -i
Change a passwordpasswd, or passwd user as root
Permissions and ownershipchmod 640 file, chown user:group file
Edit the crontabcrontab -e, list with crontab -l
What is scheduled through systemdsystemctl list-timers --all
cron field orderExample
minute hour day month weekday0 2 * * * /usr/local/bin/backup.sh runs at 02:00 daily
Every 15 minutes*/15 * * * * /usr/local/bin/check.sh
Mondays at 06:3030 6 * * 1 /usr/local/bin/weekly.sh

When the command is not there

FamilyInstall
RHEL, Rocky, AlmaLinux, Fedoradnf install tree
RHEL 7 and olderyum install tree
Debian, Ubuntuapt install tree
SLES, openSUSEzypper install tree
Photon OS, vCenter appliancetdnf install tree
Alpine, containersapk add tree
Minimal images are missing more than you expect. dig, tcpdump, lsof, tree and even ip can be absent on a container or an appliance. Check with command -v name before assuming the system is broken, and remember that an ESXi host has no package manager at all.

FAQ

Command not found, but I am sure it exists.
Three cases. It is not installed, which command -v name settles. It lives in /usr/sbin and your PATH as a normal user does not include it, so try sudo name or the full path. Or it is a shell builtin of a different shell. On minimal images and appliances the first case is by far the most common.
Which editor should I use?
nano when it is there: arrow keys work, and the shortcuts are printed at the bottom of the screen. vi is the one guaranteed to exist, including on an ESXi host, so it is worth knowing the twenty keys that get you in and out safely.
Why does my command work as root but not as me?
Usually file permissions or a PATH difference. ls -l on the file shows the first, and sudo -l shows what you are actually allowed to run. Note that sudo command and sudo -i give different environments, which is why a script can behave differently between them.
How do I run something that keeps going after I disconnect?
tmux for interactive work you want to return to, nohup ./job.sh & for a one-off, and a systemd unit for anything that should survive a reboot and be managed properly.
Is there a PowerShell equivalent on Linux?
Yes, PowerShell 7 installs on all the major distributions and your existing scripts largely work. It is a reasonable choice for your own tooling, but the system itself is administered with the commands on this sheet, so you still need both.