Stream a service's journal, starting with the last 100 lines.
service
journalctl -u <service> -f -n 100Copy What each part does journalctlread the systemd journal -u <service>only this unit -ffollow new lines -n 100start with the last 100 lines Example $ journalctl -u nginx -f -n 100
Nov 20 09:12:01 web-1 nginx[812]: 10.0.3.4 - - "GET /healthz HTTP/1.1" 200My note Add --since "10 min ago" when the service is chatty.
Only priority err and worse from the current boot: fastest way to see what's wrong on a box.
journalctl -b -p err --no-pagerCopy What each part does journalctlread the systemd journal -bthis boot only (-b -1 for the previous one) -p errpriority err and worse (crit, alert, emerg) --no-pagerprint directly Like tail -f but keeps following when logrotate replaces the file.
file
tail -F -n 200 <file> Copy What each part does tailprint the end of a file -Ffollow by name and retry: keeps going when the file is rotated or recreated (-f would stop) -n 200start with the last 200 lines <file>the log file My note -F (capital) = --follow=name --retry. -f stops after rotation.
Case-insensitive search with line numbers and 3 lines of context around each hit.
pattern file
grep -n -i -C 3 "<pattern> " <file> Copy What each part does grepsearch text -nshow line numbers -icase-insensitive -C 33 lines of context before and after each match "<pattern>" <file>what to look for, and where Example $ grep -n -i -C 3 "timeout" /var/log/app/app.logStatus, last exit code and the most recent log lines of a unit.
service
systemctl status <service> --no-pager -lCopy What each part does systemctl status <service>state, main PID, exit code, and the last log lines of the unit --no-pagerprint directly instead of opening less -ldon't truncate long lines Interactive process view sorted by CPU with full command lines. Press M to sort by memory, 1 for per-core.
What each part does toplive view of processes -cshow the full command line, not just the program name -o %CPUsort by CPU (press M to switch to memory, q to quit) My note htop is nicer if installed: htop --sort-key=PERCENT_MEM
Size, used and available space per mount, with filesystem type.
What each part does dfdisk free: size, used, available per mounted filesystem -hhuman-readable sizes (G, M) -Tshow the filesystem type (ext4, xfs, tmpfs...) Example Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p1 ext4 50G 49G 1.0G 98% /My note Also run df -i: a disk can be 'full' on inodes with space left.
Top 20 directories by size under a path, staying on one filesystem (-x).
path
sudo du -xh --max-depth=1 <path> 2>/dev/null | sort -rh | head -20Copy What each part does sudo dudisk usage of directories -xstay on one filesystem (skip other mounts) -hhuman-readable sizes --max-depth=1 <path>one total per direct subdirectory of path 2>/dev/nullhide permission errors | sort -rhsort human sizes, largest first | head -20top 20 Example $ sudo du -xh --max-depth=1 /var 2>/dev/null | sort -rh | head -20Lists open files whose link count is 0: deleted but still held open by a process, so space isn't freed.
What each part does sudo lsoflist open files (as root, to see every process) -nPno DNS or port-name lookups: faster +L1only files with link count < 1: deleted but still open; restart the process to free the space My note Restart (or truncate via /proc/<pid>/fd/<n>) the holding process to free the space.
TCP/UDP listening sockets with the PID/program that owns each one.
What each part does sudo sssocket statistics (sudo to see other users' processes) -tuTCP and UDP sockets -llistening only -pshow the owning process and PID -nnumeric ports and addresses, no name lookups Shows TLS handshake, request/response headers, final status code and total time.
url
curl -v -sS -o /dev/null -w "%{http_code} %{time_total}s\n" <url> Copy What each part does curlmake an HTTP request -vverbose: DNS, connect, TLS handshake, request and response headers -sShide the progress bar, still show errors -o /dev/nullthrow away the response body -w "%{http_code} %{time_total}s\n"after the request, print the status code and total time <url>the URL Example < HTTP/2 503
< retry-after: 30
503 0.214sQuick A/CNAME lookup. Use dig @<resolver> <hostname> to compare against a specific DNS server.
hostname
dig +short <hostname> Copy What each part does digDNS lookup tool +shortprint only the answers (IPs or CNAME targets) <hostname>the name to resolve; add @<server> to ask a specific DNS server Connect using one explicit key (avoids 'Too many authentication failures').
key-file user host
ssh -i <key-file> -o IdentitiesOnly=yes <user> @<host> Copy What each part does sshSSH client -i <key-file>use this private key -o IdentitiesOnly=yesoffer only that key, not every key in the agent (avoids Too many authentication failures) <user>@<host>who and where Forward a local port to a private host/port via a jump box. Then connect to localhost:<local-port>.
local-port target-host target-port user bastion
ssh -N -L <local-port> :<target-host> :<target-port> <user> @<bastion> Copy What each part does sshSSH client -Ndon't run a remote command: tunnel only -L <local-port>:<target-host>:<target-port>localhost:local-port forwards to target-host:target-port as seen from the bastion <user>@<bastion>the jump host to connect to Example $ ssh -N -L 5432:db.internal:5432 ops@bastion.example.comDelete archived journal files older than N days to reclaim disk.
days
sudo journalctl --vacuum-time=<days> dCopy What each part does sudo journalctlmanage the journal as root --vacuum-time=<days>ddelete archived journal files older than N days (or --vacuum-size=500M) My note Check size first: journalctl --disk-usage
Remove compressed rotated logs older than N days. Run without -delete first to preview.
days
sudo find /var/log -type f -name "*.gz" -mtime +<days> -deleteCopy What each part does sudo find /var/logsearch under /var/log as root -type ffiles only -name "*.gz"compressed rotated logs -mtime +<days>last modified more than N days ago -deletedelete matches (run without it first to see the list) First step before patching: tells you which package manager to use (dnf, yum, apt, zypper, apk) and which kernel is running now.
cat /etc/os-release && uname -rCopy What each part does cat /etc/os-releasedistro name and version (NAME, VERSION_ID, e.g. Amazon Linux 2023, Ubuntu 22.04) uname -rthe kernel that is running right now (not necessarily the newest one installed) Example $ cat /etc/os-release && uname -r
NAME="Amazon Linux"
VERSION_ID="2023"
...
6.1.112-122.189.amzn2023.x86_64Every kernel installed on the host. Compare with uname -r to see if a newer one is waiting for a reboot.
rpm -q kernel 2>/dev/null || dpkg -l 'linux-image*' | grep ^iiCopy What each part does rpm -q kernelRHEL / Amazon Linux / SUSE: installed kernel packages (AL2023 may name them kernel6.12, kernel6.18: rpm -qa "kernel*") 2>/dev/null ||not an rpm system? try dpkg dpkg -l 'linux-image*' | grep ^iiDebian / Ubuntu: installed kernel images (ii = installed) Upgrade a single package on Alpine (usually inside a container or Dockerfile).
package
Dry run first apk update && apk add --upgrade --simulate <package> Copy apk update && apk add --upgrade <package> Copy What each part does apk updaterefresh the package index apk add --upgrade <package>upgrade it to the newest version in the repo My note Everything: apk upgrade --no-cache
Scanners flag these outside the OS package list. Compare each with the "Fixed In" version from the report.
node -v; python3 --version; java -version 2>&1 | head -1; nginx -v; git --version; /opt/splunkforwarder/bin/splunk version 2>/dev/nullCopy What each part does node -vNode.js python3 --versionPython java -version 2>&1 | head -1Java (prints to stderr) nginx -vnginx git --versiongit splunk versionSplunk Universal Forwarder Puppeteer and Playwright download their own Chromium. Old copies show up as Chromium CVEs that OS patching never fixes.
sudo find / -xdev \( -name chrome -o -name chromium -o -name headless_shell \) -type f 2>/dev/nullCopy What each part does find / -xdevsearch the root filesystem only -name chrome -o -name chromium -o -name headless_shellChromium binary names -type ffiles only My note Fix it in the app: npm ls puppeteer, then npm install puppeteer@latest and redeploy. Delete stale ~/.cache/puppeteer folders.
Restart only if the config still passes after the upgrade. A reload keeps the old binary running, so restart.
Dry run first sudo dnf upgrade nginx --assumenoCopy sudo dnf upgrade nginx && sudo nginx -t && sudo systemctl restart nginxCopy What each part does dnf upgrade nginxnew nginx package (apt install --only-upgrade nginx on Ubuntu) nginx -ttest the config; stops the chain if it fails systemctl restart nginxstart the new binary Works on RHEL/Fedora/Amazon Linux, Debian/Ubuntu and Alpine. For installed vs available: apt-cache policy <package> or dnf list --showduplicates <package>.
package
rpm -q <package> 2>/dev/null || dpkg-query -W -f='${Package} ${Version}
' <package> 2>/dev/null || apk info -v <package> Copy What each part does rpm -q <package>RHEL family and SUSE: name-version-release, or 'not installed' 2>/dev/null ||hide 'command not found' and try the next package manager dpkg-query -W -f='${Package} ${Version}
' <package>Debian / Ubuntu: name and installed version apk info -v <package>Alpine: name-version Example $ rpm -q openssl 2>/dev/null || dpkg-query -W -f='${Package} ${Version}\n' openssl 2>/dev/null || apk info -v openssl
openssl 3.0.13-0ubuntu3.4My note To check many servers at once, run the same line through Ansible: ansible all -i <inventory> -m shell -a "...".
No commands match these filters. Clear filters