Linux commands for system administrators: terminal with ps, ss, journalctl, lsof and lvextend examples

This page collects the Linux commands for system administrators that you will type in your first months on the job: how to look at a server you have never seen, find what is eating the memory or the disk, read the logs, and manage services, users, storage and packages without breaking anything. Each command has a one-line explanation in plain English, an example you can copy and a label that tells you how careful to be.

The commands were checked for Rocky Linux 10 (they work the same on RHEL 10, AlmaLinux 10 and Oracle Linux 10) and for Ubuntu Server 26.04 LTS. Where the two families do things differently, a small grey line under the description shows both.

Look at the label before you press Enter: Read only commands only look, and Changes commands change the system, so do them in a planned slot. Danger commands can delete data, cut users off or lock you out, so check twice and get a second pair of eyes.

To practise every group below on your own laptop, the Linux Administration course builds a two-VM VirtualBox lab (rocky01 on 10.10.10.11 and ubu01 on 10.10.10.21) and the examples on this page use the same names, so you can follow along. If you are new to the job, start with what a Linux administrator does all day.

On this page: Rocky vs Ubuntu · look around · processes · network · logs · files and disk space · services · users and permissions · storage and LVM · packages · firewall · schedules and backups · kernel settings · recipes · commands people get wrong · questions

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the server name, the user, the disk or device name, the path and the sizes. These examples were tested in our lab, not on your system. At work, run the read-only commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run these commands at your own risk.

Rocky Linux and Ubuntu: what differs

Most commands are the same on both families because they come from the same upstream projects (systemd, util-linux, procps, iproute2, LVM). The differences are in packaging, file names and a few defaults, and these are the ones that trip people up when they move between the two.

Thing Rocky Linux / RHEL Ubuntu Server
Packages dnf, rpm apt, dpkg
Admin group for sudo wheel sudo
General log file /var/log/messages /var/log/syslog (RFC 3339 timestamps)
Login and sudo log /var/log/secure /var/log/auth.log
Network config NetworkManager with nmcli, keyfiles in /etc/NetworkManager/system-connections/ netplan YAML in /etc/netplan/
Firewall firewalld (firewall-cmd), on by default ufw, installed but inactive
SSH and cron units sshd, crond ssh, cron
Default file system XFS (grows, never shrinks) ext4
Access control layer SELinux, enforcing AppArmor

Look around: what is this server?

Run these before you change anything, on any server you log in to for the first time. None of them changes the system, so they are safe on production. Lesson: how to build a Linux command.

Command What it does Example Risk
hostnamectl Hostname, OS, kernel, and whether it is a VM or physical. hostnamectl Read only
cat /etc/os-release Distribution name and version, in a form scripts can read.Rocky/RHEL: ID="rocky" Ubuntu: ID=ubuntu cat /etc/os-release Read only
uname -r The kernel that is running now. After a kernel update it shows the old one until you reboot. uname -r Read only
w Uptime, load average for 1, 5 and 15 minutes, and who is logged in. w Read only
nproc Number of CPUs. Compare it with the load average. nproc
lscpu
Read only
free -h Memory and swap. Read the available column, because Linux uses spare memory for cache. free -h Read only
df -hT Disk use per file system, with its type, leaving out the in-memory ones. df -hT -x tmpfs -x devtmpfs Read only
lsblk -f Disks, partitions, LVM volumes and file systems as a tree, with mount points. lsblk -f Read only
ip -br address Every interface with its state and IP addresses, one line each. ip -br address Read only
systemctl --failed Services that failed since boot. systemctl --failed Read only
journalctl -p err -b Errors and worse since the last boot. sudo journalctl -p err -b --no-pager | tail -n 30 Read only
last Recent logins and reboots.Ubuntu: on 26.04 it comes from the wtmpdb package; the options are the same. last -n 10 Read only

Build it with your own values: Server health check (first five minutes)

Processes: what is using the CPU and memory?

When someone says “the server is slow”, these show you which program is to blame and how long it has been running. Lessons: processes and signals and check memory usage in Linux.

Command What it does Example Risk
ps aux --sort=-%mem Top 10 processes by memory. The first line is the header, so ask head for 11. ps aux --sort=-%mem | head -n 11 Read only
ps -eo ... --no-headers The same list with only the useful columns and no header (RSS is real memory in KiB). ps -eo pid,user,%mem,rss,cmd --sort=-%mem --no-headers | head -n 10 Read only
top -b -n 1 -o %CPU One copyable snapshot of top, sorted by CPU. top prints 7 lines before the first process. top -b -n 1 -o %CPU | head -n 17 Read only
ps aux --sort=-%cpu CPU averaged over each process’s life, which is different from what top shows right now. ps aux --sort=-%cpu | head -n 11 Read only
pgrep -a Is it running? PIDs with the full command line. For Java apps, search the command line with -af. pgrep -a nginx
pgrep -af java
Read only
ps -C One program’s processes with parent PID, user and how long they have run (etime). ps -o pid,ppid,user,%cpu,%mem,etime,cmd -C nginx Read only
ps ... stat Processes in the D state, which are stuck waiting for disk or NFS. ps -eo pid,stat,cmd | awk '$2 ~ /^D/' Read only
renice Lowers the priority of a running process so others get the CPU first. sudo renice -n 10 -p 12345 Changes
kill -TERM Asks a process to stop cleanly. Use systemctl stop if the process belongs to a service. sudo kill -TERM 12345 Danger
kill -KILL Stops a process at once with no clean-up. Last resort, after TERM and a wait. sudo kill -KILL 12345 Danger

Build it with your own values: Top processes by memory · Top processes by CPU · Find a process by name · Stop a process safely

Network: addresses, ports and names

Most “the application is down” tickets end up here. Check that the service listens, that the port is reachable from the other side, and that the name resolves to the right address. Lessons: the ss command, static IP with nmcli and static IP with netplan.

Command What it does Example Risk
ip route The routing table, including the default gateway. ip route Read only
ip route get Which interface and gateway the server would use to reach one address. ip route get 10.50.1.10 Read only
ss -tulnp Every listening TCP and UDP port with the program that holds it. sudo shows other users’ programs. sudo ss -tulnp Read only
ss 'sport = :PORT' Only one local port, matched by ss itself, so 3306 doesn’t also match 33060. sudo ss -tulnp 'sport = :3306' Read only
nc -zv Tests whether a port on another server answers, giving up after 3 seconds.Rocky/RHEL: dnf install nmap-ncat Ubuntu: apt install netcat-openbsd nc -zv -w 3 10.10.10.21 22 Read only
/dev/tcp The same test with bash alone, for servers without nc. timeout 3 bash -c '</dev/tcp/10.10.10.21/22' && echo "port open" || echo "port closed or filtered" Read only
getent hosts Resolves a name the way applications do: /etc/hosts first, then DNS. getent hosts ubu01.saatlab.test Read only
dig +short Asks DNS directly and skips /etc/hosts. A different answer from getent means a hosts entry is in the way.Rocky/RHEL: package bind-utils Ubuntu: package bind9-dnsutils dig +short ubu01.saatlab.test Read only
resolvectl status Which DNS server each interface uses (systemd-resolved).Ubuntu: used by default. Rocky/RHEL: read nmcli device show instead. resolvectl status Read only
nmcli connection show NetworkManager profiles and the devices they are on.Rocky/RHEL: the normal tool. Ubuntu Server uses netplan. nmcli connection show Read only
nmcli ... ipv4.method manual Gives a profile a fixed address, gateway and DNS that survive a reboot.Over SSH this cuts your session if you change the address you are connected on. RHEL 10 no longer reads ifcfg files. sudo nmcli connection modify "enp0s3" ipv4.method manual ipv4.addresses 10.10.10.11/24 ipv4.gateway 10.10.10.1 ipv4.dns "10.10.10.1"
sudo nmcli connection up "enp0s3"
Danger
nmcli +ipv4.routes Adds a static route to the profile, so it comes back after a reboot. sudo nmcli connection modify "enp0s3" +ipv4.routes "10.50.0.0/16 10.10.10.1"
sudo nmcli connection up "enp0s3"
Changes
netplan try Applies a changed netplan file and rolls it back after 120 seconds unless you press Enter. Run netplan generate first to check the YAML.Ubuntu: the way to change IPs and routes. Use spaces in the YAML, never tabs. sudo netplan generate
sudo netplan try
Changes

Build it with your own values: Who is listening on a port · Test a port on another server · Set a static IP (nmcli) · Add a static route that survives reboot · Static IP and route with netplan · Check name resolution

Logs: what went wrong and when?

Both families keep logs in two places: the systemd journal (read with journalctl, the same everywhere) and the classic text files written by rsyslog, whose names differ. Lesson: Linux log analysis.

Command What it does Example Risk
journalctl -p err --since Errors and worse in a time window, in plain words or as a date. sudo journalctl -p err --since "today" --no-pager Read only
journalctl -u One service’s messages in a time window. sudo journalctl -u nginx --since "1 hour ago" --no-pager Read only
journalctl -xeu The last lines of a service with explanations. The first thing to read when a service won’t start. sudo journalctl -xeu nginx --no-pager | tail -n 40 Read only
journalctl -b -1 Errors from the boot before this one, for “why did it reboot?”. Needs the journal kept on disk in /var/log/journal. sudo journalctl -b -1 -p err --no-pager Read only
journalctl -k Kernel messages for this boot: disk errors, OOM kills, link up and down. sudo journalctl -k --no-pager | tail -n 50 Read only
grep the system log Searches the classic log file, ignoring case.Rocky/RHEL: /var/log/messages Ubuntu: /var/log/syslog sudo grep -i "error" /var/log/messages | tail -n 50 Read only
awk fields Prints the timestamp, host and program from matching lines. The field numbers differ by distribution.Ubuntu: one RFC 3339 timestamp field, so $1, $2, $3. Rocky/RHEL: Oct 27 11:45:02 is three fields, so $1, $2, $3, $4, $5. sudo grep -i "error" /var/log/syslog | awk '{print $1, $2, $3}' | tail -n 50 Read only
zgrep Searches rotated, compressed logs without unpacking them.Rocky/RHEL: rotated files are named like messages-20261025 and are plain text by default, so use grep. sudo zgrep -i "error" /var/log/syslog.*.gz Read only
failed SSH logins Failed password and unknown-user attempts.Rocky/RHEL: /var/log/secure, unit sshd. Ubuntu: /var/log/auth.log, unit ssh. sudo grep -E "Failed password|Invalid user" /var/log/secure | tail -n 30 Read only
count by IP Counts failed logins per source address, busiest first. sudo grep "Failed password" /var/log/secure | grep -oE 'from [0-9.]+' | sort | uniq -c | sort -rn | head Read only
journalctl --vacuum-size Deletes the oldest journal files until the journal fits the size. Those logs are gone for good. sudo journalctl --vacuum-size=500M Danger

Build it with your own values: Search the system log for errors · One service’s logs · Failed SSH logins

Files and disk space

A full file system stops databases, logs and logins, so this group gets used more than any other. Find the space first, then clean up with a dry run before anything is deleted. Lessons: the find command and when du and df don’t match.

Command What it does Example Risk
df -i Inodes (file slots) used. A disk can be “full” with free space if millions of tiny files used every inode. df -i /var Read only
du --max-depth=1 Folder sizes one level down, biggest first, staying on one file system. sudo du -xh --max-depth=1 /var 2>/dev/null | sort -rh | head -n 15 Read only
find -size Files bigger than a size, biggest first. sudo find /var -xdev -type f -size +100M -exec ls -lh {} + 2>/dev/null | sort -k5 -rh | head -n 20 Read only
find -mtime -print Dry run: lists old files that match, without touching them. sudo find /var/log -xdev -type f -name '*.gz' -mtime +30 -print Read only
find ... | wc -l Counts the same list, and adds up its size. sudo find /var/log -xdev -type f -name '*.gz' -mtime +30 -print | wc -l
sudo find /var/log -xdev -type f -name '*.gz' -mtime +30 -exec du -ch {} + | tail -n 1
Read only
find -delete Deletes what the same find matched. Keep -delete as the last option on the line. sudo find /var/log -xdev -type f -name '*.gz' -mtime +30 -delete Danger
lsof +L1 Files that were deleted but are still held open by a process, so their space isn’t freed yet. sudo lsof +L1 Read only
/proc/PID/fd The same check without lsof. sudo find /proc/[0-9]*/fd -lname '*(deleted)' -printf '%p -> %l\n' 2>/dev/null Read only
truncate -s 0 Empties a file in place. Safer than rm for a log that a service still writes to. On a deleted-but-open file, use its /proc path. sudo truncate -s 0 /var/log/app/debug.log
sudo truncate -s 0 /proc/2481/fd/7
Danger

Build it with your own values: Find and delete old files (dry run first) · Biggest folders · Biggest files · Deleted files still using space

Services with systemd

systemd starts, stops and watches services on both families, so these commands are identical; only some unit names differ (sshd on Rocky, ssh on Ubuntu). Lessons: systemctl commands and write your own systemd service.

Command What it does Example Risk
systemctl status State, main PID, memory and the last log lines of a service. systemctl status nginx --no-pager Read only
is-active / is-enabled One-word answers that scripts can test. systemctl is-active nginx
systemctl is-enabled nginx
Read only
list-units Running services, or every unit file and whether it starts at boot. systemctl list-units --type=service --state=running
systemctl list-unit-files --state=enabled
Read only
enable --now Starts a service now and at every boot. sudo systemctl enable --now nginx Changes
restart / reload Restart stops and starts. Reload re-reads the config without dropping connections, if the service supports it. Test the config first. sudo nginx -t
sudo systemctl restart nginx
Changes
mask / unmask Mask links the unit to /dev/null, so nothing can start it. Stronger than disable. sudo systemctl mask nginx
sudo systemctl unmask nginx
Changes
systemctl edit Opens a drop-in override that survives package updates. sudo systemctl edit nginx Changes
daemon-reload Makes systemd re-read unit files after you change them. sudo systemctl daemon-reload Changes
systemd-analyze verify Checks a unit file for mistakes before you start it. sudo systemd-analyze verify /etc/systemd/system/disk-report.service Read only
systemctl show -p One property of a service, such as the open-files limit it got. systemctl show nginx -p LimitNOFILE Read only

Build it with your own values: Start a service and enable it at boot · Restart a service and check it · Stop a service from ever starting (mask) · Create a systemd service file · Raise a service’s open-files limit

Users, groups and permissions

Joiners, leavers and “I can’t open this folder” tickets use the same commands on both families, but the admin group differs. On Ubuntu 26.04, sudo is sudo-rs, a rewrite in Rust, and the everyday options work the same. Lessons: Linux user management, file permissions and ACLs.

Command What it does Example Risk
id A user’s UID, primary group and every other group. id priya Read only
getent The account or group entry, from local files or a directory such as AD. getent passwd priya
getent group webteam
Read only
useradd -m Creates a user with a home folder, a shell, a full name and an extra group. sudo useradd -m -s /bin/bash -c "Priya Sharma" -G webteam priya Changes
passwd / chage -d 0 Sets a password, then forces a new one at first login. sudo passwd priya
sudo chage -d 0 priya
Changes
usermod -aG Adds a group and keeps the others. Without -a the user loses every group not listed.Rocky/RHEL: admin group wheel Ubuntu: admin group sudo sudo usermod -aG wheel priya Changes
sudo -l What sudo allows you (or, with -U, another user) to run. sudo -l
sudo -l -U priya
Read only
visudo -f Edits a sudo rule file with a syntax check, so a typo can’t lock out sudo. sudo visudo -f /etc/sudoers.d/webteam Changes
usermod -L + chage -E 0 Locks a leaver. -L locks only the password; the expiry also blocks SSH keys. sudo usermod -L arjun
sudo chage -E 0 arjun
Changes
passwd -S / chage -l Is the account locked, and when do the password and account expire? sudo passwd -S arjun
sudo chage -l arjun
Read only
chage -M -m -W Password ageing: change every 90 days, not more than once a day, warn 7 days ahead. sudo chage -M 90 -m 1 -W 7 priya Changes
ls -ld / stat Owner, group and permissions of a folder, as letters and as numbers. ls -ld /srv/projects
stat -c '%A %a %U:%G %n' /srv/projects
Read only
chown / chmod Sets owner and group, then the mode. 2770 = setgid folder, owner and group rwx, others nothing. sudo chown root:webteam /srv/projects
sudo chmod 2770 /srv/projects
Changes
find -type d / -type f Sets folders and files separately in a tree, so files don’t become executable. sudo find /srv/projects -type d -exec chmod 2770 {} +
sudo find /srv/projects -type f -exec chmod 660 {} +
Changes
getfacl / setfacl Shows ACL entries, then gives one user read access (and folder entry) without changing the owner. -d makes new files inherit it. getfacl /srv/projects/reports
sudo setfacl -R -m u:arjun:rX /srv/projects/reports
sudo setfacl -R -d -m u:arjun:rX /srv/projects/reports
Changes

Build it with your own values: Create a user (with sudo if needed) · Lock a user · Password ageing rules · Owner, group and permissions · Give one user access with an ACL

Storage and LVM

New disks, bigger LUNs and volumes that need more space without downtime. Always identify the disk with lsblk and wipefs before you write to it, because device names like sdb can change between boots. Lessons: LVM in Linux and extend LVM online.

Command What it does Example Risk
wipefs (no options) Lists file system, RAID or LVM signatures on a disk. Empty output means nothing is on it. sudo wipefs /dev/sdb Read only
pvs / vgs / lvs The three LVM layers: physical disks, volume groups (pools) and logical volumes, with free space. sudo pvs
sudo vgs
sudo lvs
Read only
pvcreate Turns a disk into an LVM physical volume. Destroys whatever was on the disk. sudo pvcreate /dev/sdb Danger
vgcreate / lvcreate Creates a volume group on the disk, then a 2 GiB volume in it. sudo vgcreate vg_data /dev/sdb
sudo lvcreate -n lv_app -L 2G vg_data
Changes
mkfs Creates a file system on the volume. Run it on the wrong device and the data there is gone.Rocky/RHEL: XFS is the default. Ubuntu: ext4 is the default (mkfs.ext4). sudo mkfs.xfs /dev/vg_data/lv_app Danger
fstab by UUID Adds a mount line by UUID, then mounts everything so a typo shows now and not at the next boot.Add nofail for data disks and SAN LUNs the server can boot without. echo "UUID=$(sudo blkid -s UUID -o value /dev/vg_data/lv_app) /srv/app xfs defaults 0 0" | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
sudo mount -a
Changes
findmnt --verify Checks /etc/fstab for mistakes. Run it before every reboot after an fstab edit. sudo findmnt --verify Read only
scsi_host scan Makes Linux look for new disks or LUNs on every adapter, without a reboot.Or rescan-scsi-bus.sh from the sg3_utils package. for h in /sys/class/scsi_host/host*; do echo "- - -" | sudo tee $h/scan >/dev/null; done Changes
device/rescan Re-reads the size of one existing disk that was made bigger. echo 1 | sudo tee /sys/class/block/sdb/device/rescan Changes
vgextend / pvresize Adds a new disk to the group, or tells LVM an existing disk grew. sudo vgextend vg_data /dev/sdd
sudo pvresize /dev/sdb
Changes
lvextend -r Grows the volume and its file system in one step, while it is mounted. sudo lvextend -r -L +2G /dev/vg_data/lv_app Changes
xfs_growfs / resize2fs Grows the file system by hand if you forgot -r. XFS takes the mount point, ext4 the device.XFS can grow but never shrink. sudo xfs_growfs /srv/app
sudo resize2fs /dev/vg_data/lv_logs
Changes
lvcreate -s Takes a snapshot of a volume before a risky change or for a backup. sudo lvcreate -s -n lv_app_snap -L 500M /dev/vg_data/lv_app Changes
lvremove Removes a volume or a snapshot. Check the name twice: on the wrong volume this deletes data. sudo lvremove -y /dev/vg_data/lv_app_snap Danger
multipath -ll SAN LUNs with each path and its state. Every LUN should show at least two active paths.Rocky/RHEL: package device-mapper-multipath Ubuntu: package multipath-tools sudo multipath -ll Read only

Build it with your own values: New disk to mounted LVM volume · Grow a logical volume online · Rescan SCSI for new or bigger disks · LVM snapshot: create, mount, remove

Packages and updates

This is where the two families differ most. Rocky uses dnf and rpm, Ubuntu uses apt and dpkg, and the left-hand column names the job so you can find both. Lessons: dnf package management and apt package management.

Command What it does Example Risk
version before install Which version you would get and from which repository.Ubuntu: apt-cache policy chrony dnf info chrony Read only
install Installs a package and what it needs.Ubuntu: sudo apt update then sudo apt install -y chrony sudo dnf install -y chrony Changes
is it installed? Shows the installed version, or says it is not installed.Ubuntu: dpkg -l chrony rpm -q chrony Read only
which package has this file? Finds the package for a command you don’t have yet, or that owns a file.Ubuntu: apt-file search semanage (needs apt-file), dpkg -S /usr/bin/lsblk dnf provides '*/semanage'
rpm -qf /usr/bin/lsblk
Read only
recently installed Packages by install date, newest first. Good for “what changed?”.Ubuntu: grep " install " /var/log/dpkg.log | tail -n 20 rpm -qa --last | head -n 20 Read only
security updates waiting Updates that fix security advisories.Ubuntu: apt list --upgradable and sudo unattended-upgrade --dry-run -v sudo dnf updateinfo list --security Read only
install security updates Installs only those updates.Ubuntu: sudo unattended-upgrade -v sudo dnf upgrade --security Changes
reboot needed? Says whether a new kernel, glibc or systemd needs a reboot.Ubuntu: ls /var/run/reboot-required sudo dnf needs-restarting -r Read only
history and undo Every transaction with its ID, what it changed, and undo for the last one.Ubuntu: no undo. Read /var/log/apt/history.log and reinstall the old version with apt install PACKAGE=VERSION. sudo dnf history list | head -n 15
sudo dnf history info last
sudo dnf history undo last
Changes
hold a version Stops one package from being upgraded.Rocky/RHEL: dnf versionlock, from the python3-dnf-plugin-versionlock package. sudo apt-mark hold nginx Changes

Build it with your own values: Install a package · Security updates · Package history and undo

Firewall

Rocky ships firewalld turned on; Ubuntu ships ufw turned off. Both write nftables rules underneath, which is why nft list ruleset shows the result on either. Lesson: Linux firewall.

Command What it does Example Risk
firewall-cmd --list-all Active zones, then everything a zone allows.Rocky/RHEL: firewalld sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --list-all
Read only
--add-port --permanent Opens a port and saves it. Without the permanent option the rule is gone at the next reload.Rocky/RHEL: firewalld sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
Changes
ufw status Whether ufw is on, and its rules with numbers.Ubuntu: ufw sudo ufw status verbose
sudo ufw status numbered
Read only
ufw allow / delete Opens a port, or removes rule number 3 from the numbered list.Ubuntu: ufw sudo ufw allow 8080/tcp
sudo ufw delete 3
Changes
ufw enable Turns the firewall on. Allow SSH first or you lock yourself out of a remote server.Ubuntu: ufw sudo ufw allow OpenSSH
sudo ufw enable
Danger
semanage port Lets a service listen on a non-standard port under SELinux.Rocky/RHEL: SELinux. Ubuntu uses AppArmor, which doesn’t label ports. sudo semanage port -a -t http_port_t -p tcp 8080 Changes
nft list ruleset The real rules in the kernel, whatever tool wrote them. sudo nft list ruleset Read only

Build it with your own values: Open a port in the firewall

Schedules and backups

Jobs that run at night, and the copies you make before a change. Lessons: Linux cron jobs and tar and rsync.

Command What it does Example Risk
crontab -l / -e Lists or edits your own scheduled jobs.Rocky/RHEL: service crond (cronie) Ubuntu: service cron crontab -l
crontab -e
Changes
cron line Runs at 02:30 every day and keeps output and errors in a log. Fields: minute, hour, day, month, weekday. 30 2 * * * /usr/local/bin/disk-report.sh >> /var/log/disk-report.log 2>&1 Changes
/etc/cron.d System jobs, with a user field after the time. The file name must not contain a dot. 30 2 * * * root /usr/local/bin/disk-report.sh >> /var/log/disk-report.log 2>&1 Changes
systemd-analyze calendar Shows when a timer expression will next fire, before you rely on it. systemd-analyze calendar "*-*-* 02:30:00" Read only
list-timers Every timer with its next and last run. systemctl list-timers Read only
enable --now a timer Starts a timer. Enable the .timer, not the .service. sudo systemctl enable --now disk-report.timer Changes
tar -czpf A dated, compressed archive of a folder, stored without the leading slash. sudo tar -czpf /root/backup/etc-$(hostname -s)-$(date +%F).tar.gz -C / etc Changes
tar -tzf / -xzf Lists an archive, or restores one file into a spare folder to compare.Create /tmp/restore first. sudo tar -tzf /root/backup/etc-rocky01-2026-10-27.tar.gz | head
sudo tar -xzf /root/backup/etc-rocky01-2026-10-27.tar.gz -C /tmp/restore etc/ssh/sshd_config
Changes
rsync --dry-run Shows what a copy would do, keeping owners, ACLs and SELinux labels. Nothing is copied. rsync -aHAX --dry-run -v /srv/app/ student@10.10.10.21:/srv/backup/app/ Read only
rsync --delete Mirrors a folder and deletes target files that are not in the source. Swap source and target by mistake and the good copy is wiped. rsync -aHAX --delete --info=progress2 /srv/app/ student@10.10.10.21:/srv/backup/app/ Danger

Build it with your own values: Cron job line · systemd timer (cron replacement) · Archive a folder with tar · Copy or mirror a folder with rsync

Kernel settings and limits

Database and Kafka install guides ask for kernel and limit changes. Make them in a file of their own so they survive a reboot and the next person can see what you changed. Lesson: sysctl kernel parameters.

Command What it does Example Risk
sysctl KEY The current value of one kernel setting. sysctl vm.swappiness Read only
sysctl -w Changes a setting now. It is lost at the next reboot. sudo sysctl -w vm.swappiness=10 Changes
/etc/sysctl.d drop-in Saves the setting in its own file and loads that file now. echo "vm.swappiness = 10" | sudo tee -a /etc/sysctl.d/90-tuning.conf
sudo sysctl -p /etc/sysctl.d/90-tuning.conf
Changes
sysctl --system Loads every sysctl file in the same order as at boot, so you see errors before the reboot does. sudo sysctl --system | tail -n 5 Changes
installed kernels Which kernels are installed and which one boots by default.Ubuntu: dpkg -l 'linux-image*' rpm -q kernel
sudo grubby --default-kernel
Read only
ulimit -n / limits The open-files limit of your shell, and of a running service process. ulimit -n
PID=$(systemctl show -p MainPID --value nginx)
grep "open files" /proc/$PID/limits
Read only

Build it with your own values: Kernel parameter that survives reboot · Raise a service’s open-files limit

Four recipes for common tickets

1. Server health check: the first five minutes

Paste the output into the ticket before you change anything. Next week, when someone asks what the server looked like before your fix, you will have the answer.

hostnamectl
cat /etc/os-release
uname -r
w
nproc
free -h
df -hT -x tmpfs -x devtmpfs
ip -br address
systemctl --failed
sudo journalctl -p err -b --no-pager | tail -n 30

Look for a load average well above nproc, almost no available memory, a file system above 90%, an interface that is DOWN, a failed service or a burst of errors. Whichever is wrong decides your next group of commands. Builder: Server health check.

2. “No space left on device”

df -h /var
df -i /var
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -rh | head -n 15
sudo find /var -xdev -type f -size +100M -exec ls -lh {} + 2>/dev/null | sort -k5 -rh | head -n 20
sudo lsof +L1

If df -i shows 100% of inodes, you are looking for millions of small files, not one big one. If du adds up to much less than df, a deleted file is still open: restart the service that lsof +L1 names and the space comes back.

Clean old files only with a dry run first, then -delete with the same filters. Builders: Biggest folders, Deleted files still using space.

3. A service won’t start

systemctl status disk-report --no-pager
sudo journalctl -xeu disk-report --no-pager | tail -n 40
sudo systemd-analyze verify /etc/systemd/system/disk-report.service
ls -l /usr/local/bin/disk-report.sh
ls -Z /usr/local/bin/disk-report.sh

status=203/EXEC means the program in ExecStart is missing or not executable, so check the path and run sudo chmod +x.

On Rocky, a script moved from your home folder keeps the wrong SELinux label, which ls -Z shows and sudo restorecon -v /usr/local/bin/disk-report.sh fixes. After any change to the unit file, run sudo systemctl daemon-reload before you start it again. Lesson: systemd service failed.

4. Add disk space to a mounted volume, online

The VMware or storage team has added a new disk (or LUN) to the server. Rescan, check that the new disk is empty, add it to the volume group and grow the volume with its file system:

lsblk
for h in /sys/class/scsi_host/host*; do echo "- - -" | sudo tee $h/scan >/dev/null; done
lsblk
sudo wipefs /dev/sdd
sudo pvcreate /dev/sdd
sudo vgextend vg_data /dev/sdd
sudo lvextend -r -L +2G /dev/vg_data/lv_app
df -h /srv/app

If they made an existing disk bigger instead, swap the middle lines for echo 1 | sudo tee /sys/class/block/sdb/device/rescan and sudo pvresize /dev/sdb. On a multipath LUN, rescan every path and run sudo multipathd resize map NAME before pvresize. Builder: Grow a logical volume online.

Commands people get wrong

These come from old runbooks, forum answers and copy-paste notes. Most of them almost work, which is why they survive for years.

You may see What goes wrong Use this instead
ps aux --sort=-%mem | head -n 10 Shows only nine processes, because the first line is the header. ps aux --sort=-%mem | head -n 11
lsof | grep deleted Lists every open file on the server first, which is slow on a busy box. sudo lsof +L1
find /var/log -name '*.gz' -mtime +30 -exec rm -f {} \; Deletes with no preview and starts one rm per file. The same find with -print first, then -delete as the last option
find /data -delete -name '*.tmp' find reads options in order, so it deletes everything under /data before it filters. find /data -name '*.tmp' -delete, after a dry run
awk '{print $1, $2, $3}' on Ubuntu syslog Written for “Oct 27 11:45:02”. Ubuntu 24.04 and later write one RFC 3339 field, so you get timestamp, host and program instead of the date. Count the fields on a real line first, or use journalctl -p err --since "today"
/etc/sysconfig/network-scripts/route-enp0s3 Only works for old ifcfg profiles (RHEL 7 and 8). RHEL 9 uses keyfiles and RHEL 10 dropped ifcfg, so the route never appears. nmcli connection modify "enp0s3" +ipv4.routes "10.50.0.0/16 10.10.10.1"
ip route add 10.50.0.0/16 via 10.10.10.1 Works until the next reboot, then the route is gone. The nmcli line above (Rocky) or a routes entry in netplan (Ubuntu)
sudo echo "- - -" > /sys/class/scsi_host/host0/scan Permission denied: the redirect runs as you, not root. It also scans only host0, and a rescan of the host never picks up a bigger disk. The tee loop over every host, and echo 1 | sudo tee /sys/class/block/sdb/device/rescan for a resized disk
sysctl -w or edits to /etc/sysctl.conf -w is lost at reboot. One big sysctl.conf is hard to review and mixes everyone’s changes. /etc/sysctl.d/90-name.conf, then sudo sysctl --system
usermod -G webteam priya Replaces every other group of priya, including wheel or sudo. sudo usermod -aG webteam priya
usermod -L for a leaver Locks the password only. SSH keys still log in. Also sudo chage -E 0 arjun and remove their keys
ss -tulnp | grep :3306 Also matches 33060 (the MySQL X port) and any other port starting with 3306. sudo ss -tulnp 'sport = :3306'
chmod -R 770 /srv/projects Every file inside becomes executable. find with -type d and -type f separately
/etc/security/limits.conf for a service systemd services don’t read it, so “Too many open files” stays. A LimitNOFILE= drop-in, see the builder task

Common questions

Do these commands work on RHEL, AlmaLinux and Oracle Linux too? Yes. Rocky, AlmaLinux and Oracle Linux are rebuilt from the same RHEL sources, so the packages, paths and options match. The one visible difference is on Oracle Linux with the UEK kernel, where uname -r shows a UEK version string.

Why do some read-only commands need sudo? They read other users’ data. ss -p needs root to show other users’ processes, lsof to see every open file, and journalctl to read system logs (members of the adm, wheel or systemd-journal groups can read the journal without sudo).

Where are ifconfig and netstat? They come from the old net-tools package, which neither family installs by default. Use ip -br address in place of ifconfig and ss -tulnp in place of netstat; they show more and they are what current documentation uses.

What does the load average tell me? The average number of processes running or waiting over 1, 5 and 15 minutes. Compare it with nproc: a load of 8 on 8 CPUs is busy but fine, a load of 8 on 2 CPUs is a queue. High load with low CPU use usually means processes stuck on disk or NFS, which the D-state check in the processes table finds.

Rocky or Ubuntu: which should I learn first? Learn both, but start with the one your target employers run. In Indian enterprise jobs (banks, telecom, SAP, storage) the RHEL family is more common; cloud and start-up jobs use more Ubuntu. Nine commands out of ten on this page are the same on both.

How do I practise the Danger commands without risk? In a VM you can throw away. Take a VirtualBox snapshot, run the command, see what breaks and restore. The lab setup lesson shows the setup, and every lesson in the course has a “break it, then fix it” lab built that way.

Further reading: Linux commands for system administrators

Official references: Red Hat Enterprise Linux 10 documentation, Rocky Linux documentation, Ubuntu Server documentation and the Linux man pages on man7.org. To learn each group step by step on your own lab, take the Linux Administration course, and keep the Linux commands cheat sheet open while you work.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.