Linux Cheatsheet

Linux command cheatsheet

The commands from the Linux series, collected in one place — the dog-eared card for when you’re staring at a strange prompt and just need the thing. Grouped by what you’re trying to do. Examples are Debian/Ubuntu-flavoured (apt); where RHEL/AlmaLinux differs, it’s noted.

Orient yourself

CommandWhat it tells you
whoamiwhich user you are
idyour user, groups, and whether you can sudo
hostnamectlthe machine’s name, OS and kernel
uname -akernel version and architecture
uptimehow long it’s been up, and system load
w / whowho else is logged in

Move around

CommandWhat it does
pwdwhere am I (print working directory)
ls -lalist everything here, long form, incl. hidden
cd <dir>change directory
cd ~go to your home directory
cd -back to the previous directory
cd ..up one level

Look inside files

CommandWhat it does
cat <file>dump a file to the screen
less <file>page through a file (q to quit)
head -n 20 <file>the first 20 lines
tail -n 20 <file>the last 20 lines
tail -f <file>follow a file live — perfect for logs
grep "term" <file>find lines matching a pattern

Files & folders

CommandWhat it does
cp <src> <dst>copy a file
mv <src> <dst>move or rename
mkdir -p <path>make directories, parents included
touch <file>create an empty file / update its timestamp
rm <file>delete a file
rm -rf <dir>delete a directory and everything in it — no undo
ln -s <target> <link>make a symbolic link

Warning

There is no recycle bin at the shell. rm -rf deletes permanently and without asking — and run as root against the wrong path it will happily eat the whole system. Read the path twice, avoid running as root unless you must, and treat sudo as a deliberate act, not a reflex.

Permissions

CommandWhat it does
ls -lshow permissions, owner and group
chmod +x filemake a file executable
chmod 644 fileowner read/write, everyone else read
chmod 755 dirowner all; others read + enter
chmod -R 755 dirapply recursively to a directory
chown user:group filechange owner and group
chmod +t dirsticky bit — only owners delete their own files
umaskshow the default permission mask

Octal maths: read = 4, write = 2, execute = 1. So 7 = rwx, 5 = r-x, 4 = r–. Files usually 644, programs & directories 755.

System state

CommandWhat it shows
ps auxevery running process
top / htoplive process & resource view (q to quit)
df -hdisk space, human-readable
free -hmemory usage
du -sh *size of each item in this directory
lsblkdisks and partitions

Services & logs (systemd)

CommandWhat it does
systemctl status <svc>is it running? plus recent logs
systemctl start|stop|restart <svc>control a service now
systemctl enable|disable <svc>start at boot (or don’t)
journalctl -u <svc> -ffollow one service’s logs live
journalctl -xerecent logs with errors highlighted

Networking (see the Networking series)

CommandWhat it shows
ip ayour addresses (the /24 and friends)
ip rrouting table and default gateway
ss -tulpnlistening ports and what’s on them
ping <host>basic reachability
dig <name> / nslookupDNS lookups
curl -I <url>fetch just the HTTP headers

Packages: apt vs dnf

TaskDebian / UbuntuRHEL / AlmaLinux
refresh indexapt update(automatic)
upgrade everythingapt upgradednf upgrade
installapt install <pkg>dnf install <pkg>
removeapt remove <pkg>dnf remove <pkg>
searchapt search <term>dnf search <term>

Getting help & getting out

Keys / commandWhat it does
man <cmd>the full manual for a command
<cmd> --helpa quick usage summary
tldr <cmd>practical examples (if installed)
Ctrl-Cstop the running command
Ctrl-Dend input / log out
qquit less, man, top
:q! then Enterescape vim without saving
Ctrl-Xexit nano

This card grows with the Linux series — each post drops its commands here so there’s always one place to look them up.