The short version of our full Linux commands guide for Red Hat, RHEL, Rocky and AlmaLinux. Use it as a quick lookup. To keep a copy, press Ctrl+P (Cmd+P on a Mac) and choose Save as PDF or print it: the page prints without menus and ads. Commands that change the system need sudo.
First 60 seconds on a server that has a problem
Command
Question it answers
systemctl --failed
Which services are broken?
journalctl -p err -b
What errors happened since boot?
df -hT; df -i
Is a disk or its inode table full?
free -h; uptime
Out of memory? Is the load higher than the CPU count (nproc)?
ss -tulpn
Is the service listening on the port?
sudo firewall-cmd --list-all
Does the firewall allow it?
getenforce; sudo ausearch -m AVC -ts recent
Is SELinux blocking it?
top then M or P
Which process uses the memory or CPU?
System and help
Command
Use
cat /etc/redhat-release
Distribution and version
hostnamectl, uname -r
Host details, kernel version
lscpu, free -h, lsblk
CPU, memory, disks
man cmd, cmd --help, man -k word
Manual, short help, search the manuals
sudo !!, Ctrl+R, history
Repeat with sudo, search history, list history
Files and text
Command
Use
ls -lah, ls -Z
List with details, with SELinux labels
cp -a src dst, mv a b, rm -ri dir
Copy (keep attributes), move or rename, delete
mkdir -p a/b/c, ln -s target link
Create folders, symbolic link
find / -xdev -type f -size +500M
Files over 500 MB on the root filesystem
find . -name "*.log" -mtime +30
Logs not changed for 30 days
grep -rn "text" /etc
Search inside files, with line numbers
grep -v "^#" file
Hide comment lines
tail -f /var/log/messages
Follow a log live
less file
Page through a file (/ search, q quit)
sed -i.bak 's/old/new/g' file
Replace text, keep a backup
awk -F: '{print $1}' /etc/passwd
Print the first column
sort | uniq -c | sort -rn | head
Count and rank repeated lines
tar -czvf a.tar.gz dir, tar -xzvf a.tar.gz
Create, extract (-tzf lists)
du -sh /var/* | sort -h
Folder sizes, smallest first
cmd > f, cmd >> f, cmd 2>&1
Overwrite, append, merge errors into output
Permissions, users and sudo
Command
Use
chmod 644 f, chmod 755 f, chmod 600 key
Files, scripts and folders, private keys
chown user:group f, chown -R apache: dir
Change owner and group
setfacl -m u:alice:rwx dir, getfacl dir
Extra access for one user, view ACLs
useradd -m -s /bin/bash -G wheel bob
New user with admin rights (wheel = sudo)
usermod -aG group bob
Add to a group (always with -a)
passwd bob, chage -l bob, usermod -L bob
Set password, password age, lock account
id bob, last -n 20, sudo lastb
Groups, recent logins, failed logins
sudo visudo
Edit sudo rules safely
Packages: dnf and rpm
Command
Use
dnf check-update, sudo dnf upgrade
List updates, install them
sudo dnf upgrade --security
Security updates only
sudo dnf install pkg, sudo dnf remove pkg
Install, remove
dnf search word, dnf info pkg
Search, details
dnf provides */bin/dig
Which package has this command or file
dnf history, sudo dnf history undo N
Past transactions, reverse one
dnf repolist, sudo dnf clean all
Repositories, clear cache
sudo dnf install epel-release
Enable EPEL (Rocky, AlmaLinux)
sudo dnf config-manager --set-enabled crb
Enable the CRB repository
dnf module list, sudo dnf module enable name:ver
AppStream version streams
rpm -qa | grep word, rpm -qf /path, rpm -ql pkg
Installed packages, owner of a file, files of a package
rpm -V pkg
Check files against the package
sudo subscription-manager status
RHEL subscription state
Services and logs: systemd
Command
Use
systemctl status nginx
State and last log lines
sudo systemctl start|stop|restart|reload nginx
Control a service now
sudo systemctl enable --now nginx
Start now and at every boot
sudo systemctl disable --now nginx
Stop and do not start at boot
systemctl cat nginx, sudo systemctl edit nginx
Show the unit, override it safely
sudo systemctl daemon-reload
After changing unit files or fstab
systemctl list-timers
Scheduled timers
journalctl -u nginx -f
Follow one service’s log
journalctl -b -p err
Errors since boot (-b -1 = previous boot)
journalctl --since "1 hour ago"
Recent logs
systemd-analyze blame | head
Slowest units at boot
Text logs: /var/log/messages, /var/log/secure (logins, sudo), /var/log/audit/audit.log, /var/log/dnf.log.
Processes and performance
Command
Use
ps aux --sort=-%mem | head
Top memory users
pgrep -a name, pkill name
Find or stop by name
kill PID, kill -9 PID
Ask to stop, force (last resort)
vmstat 2 5, iostat -xz 2
Memory, CPU and disk activity (iostat is in sysstat)
sudo lsof -i :443, sudo lsof +L1
Who uses a port, deleted files still open
nohup cmd > out.log 2>&1 &, tmux
Keep a job running after you log out
Disks, LVM and filesystems
Command
Use
lsblk -f, blkid, findmnt
Devices, UUIDs, mounts
pvs; vgs; lvs
LVM overview
pvcreate /dev/sdb
Prepare a disk (check the name first!)
vgcreate data /dev/sdb, vgextend vg /dev/sdc
New volume group, add a disk
lvcreate -n logs -L 20G data
New logical volume
mkfs.xfs /dev/data/logs
Create an XFS filesystem
lvextend -r -L +10G /dev/rhel/root
Grow a volume and its filesystem online
xfs_growfs /mount, resize2fs /dev/vg/lv
Grow XFS, grow ext4 (XFS cannot shrink)
mount -a
Test /etc/fstab after editing it
swapon --show
Swap in use
Network, time and firewall
Command
Use
ip -br a, ip route
Addresses, routes (replaces ifconfig, route)
ss -tulpn
Listening ports (replaces netstat)
ping -c 4 host, tracepath host
Reachability, path
dig example.com, curl -I https://site
DNS lookup, HTTP headers
nc -zv host 443
Test a TCP port
nmcli device status, nmcli connection show
Network devices and profiles
nmcli con mod ens18 ipv4.method manual ipv4.addresses 10.0.0.5/24 ipv4.gateway 10.0.0.1 ipv4.dns 1.1.1.1
Static IP (then nmcli con up ens18)
hostnamectl set-hostname name
Set the host name
timedatectl, chronyc tracking
Time zone, clock accuracy
firewall-cmd --list-all
Current firewall rules
firewall-cmd --permanent --add-service=https
Open a service (then --reload)
firewall-cmd --permanent --add-port=8080/tcp
Open a port (then --reload)
SELinux
Command
Use
getenforce, sestatus
Current mode
sudo setenforce 0 / 1
Permissive / enforcing until reboot (testing only)
ls -Z, ps -eZ
Labels of files and processes
sudo restorecon -Rv /path
Reset files to the correct label
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?"
Label rule for a custom folder (then restorecon)
sudo semanage port -a -t http_port_t -p tcp 8088
Allow a non-standard port
getsebool -a | grep httpd, sudo setsebool -P name 1
List and set booleans permanently
sudo ausearch -m AVC -ts recent | audit2why
Why was it denied?
SSH, copy, schedule, containers
Command
Use
ssh -p 2222 user@host, ssh -J bastion user@host
Log in on another port, through a jump host
ssh-keygen -t ed25519, ssh-copy-id user@host
Create a key, install it on a server
scp f user@host:/tmp/
Copy a file to a server
rsync -avz --progress src/ user@host:/dst/
Copy only what changed (add --dry-run first)
sudo sshd -t
Check sshd_config before reloading
crontab -e, crontab -l
Edit, list your cron jobs
30 2 * * * cmd
Cron line: every day at 02:30 (min hour day month weekday)
podman run -d --name web -p 8080:80 IMAGE
Start a container
podman ps -a, podman logs -f web, podman exec -it web sh
List, logs, shell inside
Old command, new command
Old
Now
yum
dnf
service x restart, chkconfig
systemctl restart x, systemctl enable x
ifconfig, route, netstat
ip a, ip route, ss
iptables
firewall-cmd
ntpd
chronyd
docker
podman
Five rules
Test before you reload: sshd -t, nginx -t, httpd -t, visudo -c, mount -a.
Keep a second SSH session open when you change SSH, the network or the firewall.
Back up a file before editing it: cp -a file file.bak-$(date +%F).
Do not turn off SELinux or the firewall to “fix” a problem: find the one missing rule.
Double-check paths and devices before rm -rf, dd, mkfs and chmod -R.
Learn Bash scripting from your first script to a safe backup script: variables, quoting, loops, functions, exit codes and set -euo pipefail, with real…