| Distribution | The Linux kernel plus tools and a package manager: Ubuntu and Debian (apt), RHEL, AlmaLinux and Rocky (dnf) | Linux and distributions |
cat /etc/os-release | Which distribution and version this machine runs | Linux and distributions |
whoami hostname pwd ls | Which account, which machine, which directory, what is in it | First commands |
Tab / up arrow / Ctrl-C / exit | Complete a name / recall a command / stop a command / end the session | First commands |
man 5 passwd | Ask for a section: 1 commands, 2 system calls, 5 file formats, 8 admin | Manual pages |
man -k word | Search every manual page's one-line summary | Manual pages |
cd dir / cd .. / cd / cd - | Into a directory / up one / home / back to the previous one | Moving around |
/etc /var /usr /home /tmp | Settings, changing data, installed software, users' files, scratch | Filesystem hierarchy |
/proc /sys | Not on disk: the kernel answering as files | /proc and /sys |
findmnt / df -hT | Which file system is mounted where, and its type and free space | Filesystem hierarchy |
mkdir d cp a b mv a b rm f | Make a directory, copy, move or rename, delete (no undo) | Copy, move, delete |
cp -r / rm -r | Copy / delete a directory with everything inside it | Copy, move, delete |
ls logs/*.log | A star matches any characters: list with a pattern before deleting with it | Copy, move, delete |
mv within one file system | Only renames: instant whatever the size | Copy, move, delete |
ls -i / stat file | The inode number, and everything the inode holds | Inodes |
ln target name | Hard link: a second name for the same inode, same file system only | Hard and symbolic links |
ln -s target name | Symbolic link: a small file holding a path; breaks if the target moves | Hard and symbolic links |
ls -l first letter | - file, d directory, l link, b block device, c character device, s socket, p pipe | Hard and symbolic links |
find / -name '*.conf' -size +1M -mtime -7 | Walk the tree and test every file by name, size and age | Finding files |
find … -exec cmd {} + | Run a command on everything found | Finding files |
tar -czf a.tgz dir / tar -xzf a.tgz | Bundle and gzip a folder / unpack it (j for bzip2, J for xz) | Archives and compression |
tar -tf a.tgz | List what is inside before unpacking | Archives and compression |
wc -l f / head f / tail f | Count lines / first ten / last ten (`-n 5` for five) | Viewing files |
less f | Page through: Space next screen, `/text` search, `n` next match, `G` end, `q` quit | Viewing files |
tail -f f | Follow a file and print new lines as they are written; Ctrl-C stops | Viewing files |
| nano: Ctrl-O / Ctrl-X / Ctrl-W | Save / leave / search | Editors |
vim: Esc :wq / Esc :q! | Save and quit / quit without saving | Text editors |
cp -a f f.bak … diff f.bak f | Copy before editing, then see exactly what changed | Changing settings safely |
sshd -t / nginx -t / visudo -c | Check a settings file before the service reloads it | Changing settings safely |
| 0 1 2 | Standard input, standard output, standard error | Standard streams |
> file / >> file | Send output to a file, replacing / appending | Redirection |
2> file / 2>&1 | Send errors to a file / to wherever output goes now | Redirection |
cmd > out 2>&1 | Both streams to one file; order matters, left to right | Redirection |
a | b | a's output becomes b's input; both run at once | Pipes |
grep 'text' file | Print the lines that contain the text; `-c` count, `-n` line numbers, `-i` any case, `-v` invert | grep |
grep -r text dir | Search every file under a directory | grep |
cut -d, -f2 wc -l tr a-z A-Z tee | One column, count lines, translate characters, copy to a file and on | Text tools |
cmd <<EOF … EOF | Here-document: a block of lines as input | Here-documents |
sort | uniq -c | sort -rn | head | Count repeated lines, most common first | Pipelines |
grep -E 'a|b' file | Lines matching a regular expression; -i ignore case, -v invert, -r recurse | Regular expressions |
^ $ . * [abc] | Start, end, any character, repeat, any one of | Regular expressions |
sed 's/old/new/g' file | Replace on every line; -i edits the file in place | sed |
awk -F: '$3 >= 1000 {print $1}' /etc/passwd | Split into fields, filter, print a column | awk |
| Expansion order | Braces, tilde, parameters, command substitution, arithmetic, splitting, globs | Shell expansion |
'single' / "double" | Single quotes stop every expansion; double quotes keep $ but stop splitting and globs | Quoting |
name=value / $name / ${name} | Set a shell variable (no spaces) / read it / read it where more text follows | Variables |
$(command) | Command substitution: the output of the command, as text | Variables |
export NAME=value | Copy a variable into every program started from this shell | Environment variables |
env | The environment a program actually receives | Environment variables |
~/.bashrc / ~/.bash_profile | Interactive shells / login shells read these at start | Startup files |
type ls | Is it an alias, a builtin, a function or a file, and which one runs | Command search and PATH |
echo "$PATH" | The folders searched, left to right; the first match wins | Command search and PATH |
echo $? | Exit status of the last command: 0 is success, anything else is a failure | Exit status |
cmd1 && cmd2 / cmd1 || cmd2 | Run the second only if the first succeeded / failed | Exit status |
Ctrl-R / !! / history | Search earlier commands / repeat the last one / list them | History and aliases |
alias ll='ls -alF' | A short name for a command; keep it in `~/.bashrc` | History and aliases |
set -x / echo the line | See the line after expansion, before it runs | Lab |
ls -l file and id | The two sides of every "Permission denied": the file’s owner, group and bits; your user and groups | Permission denied |
id user | UID, primary group and every group the kernel will check | Users and groups |
/etc/passwd /etc/shadow /etc/group | Accounts; hashes and ageing; group members | /etc/shadow |
rwxr-x--- = 750 | r 4, w 2, x 1, for owner, group, others | File permissions |
chmod 640 f / chmod g+w f | Set all bits / change one | File permissions |
chmod u+x f / chgrp g f / chown u:g f | Add execute for the owner / change the group / change owner and group (root) | chmod, chgrp, chown |
| Check order | Owner, else group, else others: only one set applies | Permission checks |
| Directory bits | r list names, w create and delete inside, x enter | Directory permissions |
umask 022 | New files 644, new folders 755 | Directory permissions |
| setuid 4, setgid 2, sticky 1 | Run as owner; inherit folder's group; only owners delete (as /tmp) | Directory permissions |
chmod 2770 /srv/team | Shared team folder: new files keep the team's group | Directory permissions |
setfacl -m u:ana:rw f / getfacl f | Give one more user access / read the list | Directory permissions |
sudo cmd / visudo | One command as root, logged / edit the rules safely | sudo |
useradd -m -G team ana passwd ana usermod -aG userdel -r | Create, set a password, add to a group, remove with home | Account management |
chage -M 90 -W 7 ana | Password expires after 90 days, warn 7 days before | Account management |
| Process / PID | A running copy of a program / the number that identifies it; `ps` lists, `kill PID` ends | Programs and processes |
top keys: P M k r | Sort by CPU, by memory, kill, renice | top and ps |
ps aux --sort=-%cpu | head | The busiest processes | top and ps |
ps -ef --forest / pstree | Every process and its parent, back to PID 1 | Processes |
| fork then exec | A copy of the parent, which then loads the new program | Processes |
| R S D T Z | Running, sleeping, uninterruptible (disk), stopped, zombie | Processes |
kill PID / kill -9 PID | SIGTERM 15 asks politely / SIGKILL 9 cannot be caught | Signals |
kill -HUP PID | Many daemons reload their settings on SIGHUP 1 | Signals |
Ctrl+Z bg fg jobs | Stop the foreground job, resume it behind or in front, list jobs | Job control |
cmd & / nohup cmd & | Run in the background / keep running after logout | Job control |
uptime / nproc | Load averages for 1, 5 and 15 minutes; compare with the number of CPUs | Load average |
nice -n 10 cmd / renice 5 -p PID | Start lower / change later; -20 highest, 19 lowest | Load average |
tuned-adm profile virtual-guest | Apply a set of performance settings (RHEL) | Tuning profiles |
| Service (daemon) | A program systemd starts at boot, restarts on failure and logs; controlled with `systemctl` | Services |
systemctl start / enable --now | Run now / run now and at every boot | Starting and enabling |
systemctl daemon-reload | Reread unit files after changing them | Starting and enabling |
systemctl status unit | Enabled, running, last log lines, in one screen | Service status |
journalctl -u unit -p err -b --since '1 hour ago' | Filter the journal by unit, priority, boot and time | The journal |
journalctl -f | Follow new entries as they arrive | The journal |
[Service] ExecStart= Restart=on-failure User= | The lines that turn a program into a service | Service units |
/etc/systemd/system over /usr/lib/systemd/system | Your units and overrides win over the package's | Service units |
systemctl edit unit | Write an override without touching the package's file | Service units |
Wants= vs After= | Pull in another unit / only decide the order | Service units |
| Boot order | Firmware, bootloader, kernel, initramfs, systemd as PID 1 | Boot process |
grubby --update-kernel=ALL --args=… | Change kernel boot options for good (RHEL) | GRUB |
systemctl get-default / set-default multi-user.target | Where boot ends: text or graphical | Boot process |
systemctl list-timers | Every timer and when it fires next | Scheduled jobs |
chronyc tracking / timedatectl | Is the clock synchronised, and how far off | Time synchronisation |
dpkg -L pkg / rpm -ql pkg | Which files a package installed | Packages |
dpkg -S /path / rpm -qf /path | Which package owns a file | Packages |
/etc/apt/sources.list.d/ / /etc/yum.repos.d/ | Where repositories are listed | Repositories |
apt-get install --simulate pkg | See the dependency tree before installing | Dependencies |
apt install / dnf install | Install with every dependency | apt and dnf |
apt update vs apt upgrade | Refresh the index / install newer versions | apt and dnf |
apt remove / dnf remove | Remove a package | apt and dnf |
apt search / dnf search , apt show / dnf info | Find a package, read about it | apt and dnf |
dnf provides */semanage | Which package would provide a command | apt and dnf |
[repo] name= baseurl= enabled=1 gpgcheck=1 gpgkey= | A RHEL repository file | apt and dnf |
flatpak install flathub app | A desktop app with its own runtime, sandboxed | apt and dnf |
./configure && make && sudo make install | Building from source: only when there is no package | apt and dnf |
lsblk -f | Disks, partitions, file systems, UUIDs and mount points as a tree | Block devices |
| GPT vs MBR | 128 partitions and any size, with a backup table / 4 primary, 2 TiB | Block devices |
parted /dev/sdb mklabel gpt mkpart … | Partition a disk | Adding storage |
mkfs.xfs /dev/sdb1 / mkfs.ext4 | Make a file system | Adding storage |
blkid | The UUID to put in fstab | fstab |
UUID=… /data xfs defaults 0 0 | fstab: device, mount point, type, options, dump, fsck order | fstab |
mount -a / findmnt --verify | Test fstab before you reboot | fstab |
pvcreate vgcreate lvcreate -L 10G -n data vg | Disks into a pool, volumes out of it | LVM |
lvextend -r -L +5G /dev/vg/data | Grow the volume and its file system while in use | Growing a volume |
xfs_growfs / resize2fs | Grow XFS (cannot shrink) / ext4 (can shrink offline) | Growing a volume |
mkswap swapon free -h | Make and enable swap, then check it | Growing a volume |
server:/export /mnt nfs defaults 0 0 | Mount an NFS share at boot; autofs mounts on first use | Growing a volume |
ip -br a / ip link | Addresses and link state of every interface | Interfaces |
ip route / ip route get 8.8.8.8 | The routing table / the route one address would take | Subnets and routes |
hostnamectl set-hostname web1 | Set the machine's name | Name resolution |
/etc/hosts then DNS | The order set in /etc/nsswitch.conf | Name resolution |
getent hosts name / dig name | What programs will see / what DNS alone says | Name resolution |
nmcli con mod eth0 ipv4.addresses 10.0.0.5/24 ipv4.gateway 10.0.0.1 ipv4.method manual | A fixed address that survives reboot | NetworkManager |
nmcli con up eth0 | Apply the profile | NetworkManager |
ss -tulpn | Listening TCP and UDP sockets, with the owning process | Sockets |
| 0.0.0.0 vs 127.0.0.1 | Listening on every address / only this machine | Sockets |
firewall-cmd --add-service=http --permanent && firewall-cmd --reload | Open a service for good | firewalld |
firewall-cmd --list-all | What the active zone allows | firewalld |
| Bottom up | Link, address, route, name, port, service: stop at the first failure | Troubleshooting |
ssh user@host | A shell on another machine over an encrypted connection to sshd, TCP port 22 | Logging in |
~/.ssh/known_hosts | Server keys you have trusted; a change means a warning | Known hosts |
ssh-keygen -t ed25519 | Make a key pair; the private key never leaves your machine | Key pairs |
ssh-copy-id user@host | Add your public key to the server's authorized_keys | Key pairs |
ssh -v host | Print every step of the handshake | ssh -v |
Host web HostName User IdentityFile | Short names in ~/.ssh/config | Client config |
rsync -av src/ host:dst/ | Copy only what changed; trailing slash means the contents | Copying files |
scp file host:path | Copy a whole file | Copying files |
ssh -L 8080:localhost:80 host | Local port 8080 reaches port 80 on the server | Copying files |
ssh -J jump host | Go through a bastion host | Copying files |
PermitRootLogin no PasswordAuthentication no AllowUsers | Harden sshd_config, then `sshd -t` and reload | Hardening |
semanage port -a -t ssh_port_t -p tcp 2222 | Tell SELinux before moving SSH to another port | Hardening |
#!/usr/bin/env bash | First line: which interpreter runs the file | Scripts |
chmod +x s.sh && ./s.sh | Make it runnable, then run it | Scripts |
${var:-default} ${file%.txt} ${#var} | Default value, strip a suffix, length | Expansion |
$1 $# "$@" $? | First argument, count, all arguments, last exit status | Expansion |
"$var" "${arr[@]}" | Always quote: keeps values with spaces whole | Quoting |
if [[ -f $f ]]; then …; fi | Test a file: -f file, -d folder, -z empty string | Exit codes and tests |
for f in *.log; do …; done | Loop over items | Loops |
while read -r line; do …; done < file | Loop over lines | Loops |
set -euo pipefail | Stop on the first error, unset variable or failed pipe stage | Failing safely |
trap 'echo failed at $LINENO' ERR | Say where it failed | Failing safely |
bash -x s.sh | Show every command as it really ran | Failing safely |
shellcheck s.sh | Find the classic mistakes before running | ShellCheck |
m h dom mon dow cmd | A cron line: minute, hour, day, month, weekday | Scheduling |
crontab -e / crontab -l | Edit / list your cron jobs | Scheduling |
uptime free -h df -h ss -tulpn journalctl -p err -b | First command for load, memory, disk, ports and errors | Triage |
journalctl -u nginx --since today | One unit's log for today | Logs |
systemctl status unit then journalctl -u unit -b -e | Why a service failed: the last lines, then everything since boot | A service will not start |
systemctl reset-failed unit | Clear the failed state after too many quick restarts | A service will not start |
du -xh / | sort -h | tail | The biggest folders on one file system | Disk pressure |
lsof +L1 | Deleted files still held open: space df counts but du cannot see | Disk pressure |
free -h available | Read available, not free: the cache is given back | Memory pressure |
journalctl -k | grep -i oom | Did the kernel kill a process for memory | Memory pressure |
sysctl -w key=value / file in /etc/sysctl.d/ | Change the kernel now / keep it | Memory pressure |
lsmod modprobe mod | Loaded drivers, load one | Kernel modules |
getenforce / ls -Z | SELinux mode / file labels | SELinux |
ausearch -m avc -ts recent | Read the denial | SELinux toolbox |
restorecon -Rv path / setsebool -P name on | Fix a label / turn on a boolean, for good | SELinux toolbox |
systemctl rescue / emergency | Single-user repair, with or without file systems mounted | Rescue and emergency |
rd.break at the kernel line | Stop in the initramfs to reset the root password (RHEL) | Rescue and emergency |
Nothing matches. Try a shorter word.