-rw-r--r-- 1 manu manu 1.3M Jul 6 19:58 sdb.blktrace.0 -rw-r--r-- 1 manu manu 823K Jul 6 19:58 sdb.blktrace.1 -rw-r--r-- 1 manu manu 2.8M Jul 6 19:58 sdb.blktrace.10 -rw-r--r-- 1 manu manu 1.9M Jul 6 19:58 sdb.blktrace.11 -rw-r--r-- 1 manu manu 474K Jul 6 19:58 sdb.blktrace.12 -rw-r--r-- 1 manu manu 271K Jul 6 19:58 sdb.blktrace.13 -rw-r--r-- 1 manu manu 578K Jul 6 19:58 sdb.blktrace.14 -rw-r--r-- 1 manu manu 375K Jul 6 19:58 sdb.blktrace.15 -rw-r--r-- 1 manu manu 382K Jul 6 19:58 sdb.blktrace.16 -rw-r--r-- 1 manu manu 478K Jul 6 19:58 sdb.blktrace.17 -rw-r--r-- 1 manu manu 839K Jul 6 19:58 sdb.blktrace.18 -rw-r--r-- 1 manu manu 848K Jul 6 19:58 sdb.blktrace.19 -rw-r--r-- 1 manu manu 1.6M Jul 6 19:58 sdb.blktrace.2 -rw-r--r-- 1 manu manu 652K Jul 6 19:58 sdb.blktrace.20 -rw-r--r-- 1 manu manu 738K Jul 6 19:58 sdb.blktrace.21 -rw-r--r-- 1 manu manu 594K Jul 6 19:58 sdb.blktrace.22 -rw-r--r-- 1 manu manu 527K Jul 6 19:58 sdb.blktrace.23 -rw-r--r-- 1 manu manu 1005K Jul 6 19:58 sdb.blktrace.3 -rw-r--r-- 1 manu manu 1.2M Jul 6 19:58 sdb.blktrace.4 -rw-r--r-- 1 manu manu 511K Jul 6 19:58 sdb.blktrace.5 -rw-r--r-- 1 manu manu 2.3M Jul 6 19:58 sdb.blktrace.6 -rw-r--r-- 1 manu manu 1.3M Jul 6 19:58 sdb.blktrace.7 -rw-r--r-- 1 manu manu 2.1M Jul 6 19:58 sdb.blktrace.8 -rw-r--r-- 1 manu manu 1.1M Jul 6 19:58 sdb.blktrace.9
~# bpftrace test.bpf /bpftrace/include/stdarg.h:52:1: warning: null character ignored [-Wnull-character] /lib/modules/4.19.0-8-amd64/source/arch/x86/include/asm/bitops.h:209:2: error: 'asm goto' constructs are not supported yet /lib/modules/4.19.0-8-amd64/source/arch/x86/include/asm/bitops.h:256:2: error: 'asm goto' constructs are not supported yet /lib/modules/4.19.0-8-amd64/source/arch/x86/include/asm/bitops.h:310:2: error: 'asm goto' constructs are not supported yet /lib/modules/4.19.0-8-amd64/source/arch/x86/include/asm/jump_label.h:23:2: error: 'asm goto' constructs are not supported yet /lib/modules/4.19.0-8-amd64/source/arch/x86/include/asm/signal.h:24:2: note: array'sig' declared here Attaching 1 probe... called by iptables-legacy (pid: 2981). and: 2 called by iptables-legacy (pid: 2981). and: 2
2 的含义解释如下
1 2 3 4 5 6 7 8
/usr/src/linux-headers-4.19.0-8-common/include/linux/socket.h 160/* Supported address families. */ 161#define AF_UNSPEC 0 162#define AF_UNIX 1 /* Unix domain sockets */ 163#define AF_LOCAL 1 /* POSIX name for AF_UNIX */ 164#define AF_INET 2 /* Internet IP Protocol */ 165#define AF_AX25 3 /* Amateur Radio AX.25 */ 166#define AF_IPX 4 /* Novell IPX */
Capture from all interfaces; may require superuser (sudo/su)
-i eth0
tcpdump -i eth0
Capture from the interface eth0
-c count
tcpdump -i eth0 -c 5
Exit after receiving count (5) packets
-r captures.pcap
tcpdump -i eth0 -r captures.pcap
Read and analyze saved capture file captures.pcap
tcp
tcpdump -i eth0 tcp
Show TCP packets only
udp
tcpdump -i eth0 udp
Show UDP packets only
icmp
tcpdump -i eth0 icmp
Show ICMP packets only
ip
tcpdump -i eth0 ip
Show IPv4 packets only
ip6
tcpdump -i eth0 ip6
Show IPv6 packets only
arp
tcpdump -i eth0 arp
Show ARP packets only
rarp
tcpdump -i eth0 rarp
Show RARP packets only
slip
tcpdump -i eth0 slip
Show SLIP packets only
-I
tcpdump -i eth0 -I
Set interface as monitor mode
-K
tcpdump -i eth0 -K
Don’t verify checksum
-p
tcpdump -i eth0 -p
Don’t capture in promiscuous mode
Filter Commands
Filter expression
Explanation
src host 127.0.0.1
Filter by source IP/hostname 127.0.0.1
dst host 127.0.0.1
Filter by destination IP/hostname 127.0.0.1
host 127.0.0.1
Filter by source or destination = 127.0.0.1
ether src 01:23:45:AB:CD:EF
Filter by source MAC 01:23:45:AB:CD:EF
ether dst 01:23:45:AB:CD:EF
Filter by destination MAC 01:23:45:AB:CD:EF
ether host 01:23:45:AB:CD:EF
Filter by source or destination MAC 01:23:45:AB:CD:EF
src net 127.0.0.1
Filter by source network location 127.0.0.1
dst net 127.0.0.1
Filter by destination network location 127.0.0.1
net 127.0.0.1
Filter by source or destination network location 127.0.0.1
net 127.0.0.1/24
Filter by source or destination network location 127.0.0.1 with the tcpdump subnet mask of length 24
src port 80
Filter by source port = 80
dst port 80
Filter by destination port = 80
port 80
Filter by source or destination port = 80
src portrange 80-400
Filter by source port value between 80 and 400
dst portrange 80-400
Filter by destination port value between 80 and 400
portrange 80-400
Filter by source or destination port value between 80 and 400
ether broadcast
Filter for Ethernet broadcasts
ip broadcast
Filter for IPv4 broadcasts
ether multicast
Filter for Ethernet multicasts
ip multicast
Filter for IPv4 multicasts
ip6 multicast
Filter for IPv6 multicasts
ip src host mydevice
Filter by IPv4 source hostname mydevice
arp dst host mycar
Filter by ARP destination hostname mycar
rarp src host 127.0.0.1
Filter by RARP source 127.0.0.1
ip6 dst host mywatch
Filter by IPv6 destination hostname mywatch
tcp dst port 8000
Filter by destination TCP port = 8000
udp src portrange 1000-2000
Filter by source TCP ports in 1000–2000
sctp port 22
Filter by source or destination port = 22
Display Commands
Example
Explanation
tcpdump -i eth0 -A
Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.
[![Screenshot with ASCII (sudo tcpdump twitter)
tcpdump -D
Print the list of the network interfaces available on the system and on which tcpdump can capture packets.
tcpdump -i eth0 -e
Print the link-level header on each output line, such as MAC layer addresses for protocols such as Ethernet and IEEE 802.11.
tcpdump -i eth0 -F /path/to/params.conf
Use the file params.conf as input for the filter expression. (Ignore other expressions on the command line.)
tcpdump -i eth0 -n
Don’t convert addresses (i.e., host addresses, port numbers, etc.) to names.
tcpdump -i eth0 -S
Print absolute, rather than relative, TCP sequence numbers. (Absolute TCP sequence numbers are longer.)
tcpdump -i eth0 --time-stamp-precision=nano
When capturing, set the timestamp precision for the capture to tsp: • micro for microsecond (default) • nano for nanosecond.
tcpdump -i eth0 -t
Omit the timestamp on each output line.
tcpdump -i eth0 -tt
Print the timestamp, as seconds since January 1, 1970, 00:00:00, UTC, and fractions of a second since that time, on each dump line.
tcpdump -i eth0 -ttt
Print a delta (microsecond or nanosecond resolution depending on the --time-stamp-precision option) between the current and previous line on each output line. The default is microsecond resolution.
tcpdump -i eth0 -tttt
Print a timestamp as hours, minutes, seconds, and fractions of a second since midnight, preceded by the date, on each dump line.
tcpdump -i eth0 -ttttt
Print a delta (microsecond or nanosecond resolution depending on the --time-stamp-precision option) between the current and first line on each dump line. The default is microsecond resolution.
tcpdump -i eth0 -u
Print undecoded network file system (NFS) handles.
tcpdump -i eth0 -v
Produce verbose output. When writing to a file (-w option) and at the same time not reading from a file (-r option), report to standard error, once per second, the number of packets captured.
tcpdump -i eth0 -vv
Additional verbose output than -v
tcpdump -i eth0 -vvv
Additional verbose output than -vv
tcpdump -i eth0 -x
Print the headers and data of each packet (minus its link level header) in hex.
tcpdump -i eth0 -xx
Print the headers and data of each packet, including its link level header, in hex.
tcpdump -i eth0 -X
Print the headers and data of each packet (minus its link level header) in hex and ASCII.
tcpdump -i eth0 -XX
Print the headers and data of each packet, including its link level header, in hex and ASCII.
Output Commands
Command
Example
Explanation
-w captures.pcap
tcpdump -i eth0 -w captures.pcap
Output capture to a file captures.pcap
-d
tcpdump -i eth0 -d
Display human-readable form in standard output
-L
tcpdump -i eth0 -L
Display data link types for the interface
-q
tcpdump -i eth0 -q
Quick/quiet output. Print less protocol information, so output lines are shorter.
-U
tcpdump -i eth0 -U -w out.pcap
Without -w option Print a description of each packet’s contents. With -w option Write each packet to the output file out.pcap in real time rather than only when the output buffer fills.
Miscellaneous Commands
Operator
Syntax
Example
Description
AND
and, &&
tcpdump -n src 127.0.0.1 and dst port 21
Combine filtering options joined by “and”
OR
or, \|
tcpdump dst 127.0.0.1 or src port 22
Match any of the conditions joined by “or”
EXCEPT
not, !
tcpdump dst 127.0.0.1 and not icmp
Negate the condition prefixed by “not”
LESS
less, <, (<=)
tcpdump dst host 127.0.0.1 and less 128
Shows packets shorter than (or equal to) 128 bytes in length. < only applies to length 32, i.e., <32.
GREATER
greater, >, (>=)
tcpdump dst host 127.0.0.1 and greater 64
Shows packets longer than (or equal to) 64 bytes in length. > only applies to length 32, i.e., >32.
EQUAL
=, ==
tcpdump host 127.0.0.1 = 0
Show packets with zero length
Example Usage
Example
Explanation
tcpdump -r outfile.pcap src host 10.0.2.15
Print all packets in the file outfile.pcap coming from the host with IP address 10.0.2.15
tcpdump -i any ip and not tcp port 80
Listen for non-HTTP packets (which have TCP port number 80) on any network interface
tcpdump -i eth0 -n >32 -w pv01.pcap -c 30
Save 30 packets of length exceeding 32 bytes to captures.pcap without DNS resolution on the eth0 network interface
tcpdump -AtuvX icmp
Capture ICMP traffic and print ICMP packets in hex and ASCII and the following features: With: • headers • data • undecoded NFS handles Without: • link level headers • timestamps.
tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
Print all IPv4 HTTP packets to and from port 80, i.e. print only packets that contain data, not, for example, SYN and FIN packets and ACK-only packets.
define hook-stop # There doesn't seem to be a good way to detect if we're in 16- or # 32-bit mode, but in 32-bit mode we always run with CS == 8 in the # kernel and CS == 35 in user space if $cs == 8 || $cs == 35 if $lastcs != 8 && $lastcs != 35 set architecture i386 end x/i $pc else if $lastcs == -1 || $lastcs == 8 || $lastcs == 35 set architecture i8086 end # Translate the segment:offset into a physical address printf "[%4x:%4x] ", $cs, $eip x/i $cs*16+$eip end set $lastcs = $cs end # 需要注释掉 # echo + target remote localhost:25000\n # target remote localhost:25000
Purpose: a single-page, production-ready cheatsheet for Linux/SRE triage. Optimized for fast on-call use: concise flags, copy-paste recipes, brief notes, and clear risk callouts.
Tip: Use your editor/browser search to jump to any command by its number, e.g., “## 41. lsof”.
Count unique values: awk '{c[$1]++} END{for (k in c) print k, c[k]}' file
Networking
Cheat Card - Ports→PIDs: ss -ltnp; established only: ss -tn state established - TCP detail: ss -i dst <ip> (rtt, cwnd, retrans) - Path/source IP: ip route get <dest>; counters: ip -s link show <iface> - Latency/loss: mtr -ezbw <dest>; quick traceroute ICMP: traceroute -I <dest> - Targeted capture: tcpdump -ni <iface> tcp port 443 (or port 53, icmp) - DNS: resolvectl query <name> or dig <name> A +short
5. ping
Compat: Linux; Root: may require CAP_NET_RAW depending on system; Requires: iputils-ping.
-4: ping IPv4 only
-6: ping IPv6 only
-A: adapts to roundtrip time
-b: allow pinging broadcast addresses
-I: ping through an interface
-M: set PMTU strategy
-s: set packetsize (default is 56B)
-t: set IP time-to-live
ping 224.0.0.1: ping multicast address
Notes: - Using average rtt values, you can determine whether there are huge variations causing jitter, especially in RT applications - ping will report duplications, however, duplicate packets should never occur, and seem to be caused by inappropriate link-level retransmissions - ping will report damaged packets, suggesting broken hardware in the network Requires: iputils-ping.
6. ip
Compat: Linux; Root: not required for reads; Requires: iproute2.
ip addr: Show information for all addresses
ip addr show dev wlo1: Display information only for device wlo1
ip link: Show information for all interfaces
ip link show dev wlo1: Display information only for device wlo1
ip -s: Display interface statistics (packets dropped, received, sent, etc.)
Quick recipes:
Path and source IP: ip route get <dest>
Interface counters: ip -s link show <iface> (rx/tx errors, drops)
Neighbors/ARP: ip neigh and ip neigh show dev <iface>
Multicast: ip maddr or ip maddr show dev <iface>
Example
1 2 3
# Query path and chosen source IP ip route get 8.8.8.8 # Expect: 8.8.8.8 via 192.168.1.1 dev wlo1 src 192.168.1.23
ip route: List all of the route entries in the kernel
ip route add: Add a route entry to the kernel routing table
ip route replace: Replace an existing route (add if not present)
ip maddr: Display multicast information for all devices
ip maddr show dev wlo1
ip neigh show dev wlo1: check for reachability of specific interfaces
Requires: iproute2.
7. arp
Compat: Legacy; prefer ip neigh; Requires: net-tools.
arp: show all ARP table entries
arp -d address: delete ARP entry for address
arp -s address hw_addr: set up new table entry Note: legacy from net-tools; prefer ip neigh. Requires: net-tools.
8. arping
Compat: Linux; Root/CAP_NET_RAW required; Package: arping (iputils-arping on some distros).
arping -I wlo1 192.168.0.1: send ARP requests to host
arping -D -I wlo1 192.168.0.15: check for duplicate MAC address Requires: arping (iputils-arping on some distros).
9. ethtool
Compat: Linux; Root for changing settings, read stats usually ok; Requires: ethtool.
lastsnd:<lastsnd>: how long time since the last packet sent, the unit is millisecond
lastrcv:<lastrcv>: how long time since the last packet received, the unit is millisecond
lastack:<lastack>: how long time since the last ack received, the unit is millisecond
ss -A tcp,udp: dump socket tables Requires: iproute2.
37. tcpdump
Compat: Linux; Root/CAP_NET_RAW required for captures; Requires: tcpdump. What it does: capture packets for inspection and troubleshooting. Requires: tcpdump.
Interface and no name resolution: tcpdump -ni <iface>
Host or subnet: tcpdump -ni <iface> host <ip>; tcpdump -ni <iface> net 10.0.0.0/8
Ports/protocols: tcpdump -ni <iface> tcp port 443 or udp port 53
SYNs only (new TCP handshakes):
1 2
# New TCP handshakes only (SYN without ACK) tcpdump -ni <iface> 'tcp[tcpflags] & (tcp-syn) != 0 and tcp[tcpflags] & (tcp-ack) == 0'
DNS queries: tcpdump -ni <iface> port 53
ICMP reachability: tcpdump -ni <iface> icmp
1 2 3 4 5 6
# Requires: tcpdump # Capture full packets to a file tcpdump -ni <iface> -s 0 -w capture.pcap
Compat: Linux; May need root/CAP_NET_RAW for certain probe types; Requires: mtr. What it does: combines ping and traceroute to visualize latency and loss per hop.
wAvs - Average size of packets written (transmitted).
%Util - Percentage utilization of the interface. For full-duplex interfaces, this is the greater of rKB/s or wKB/s as a percentage of the interface speed. For half-duplex interfaces, rKB/s and wKB/s are summed.
%rUtil, %wUtil - Percentage utilization for bytes read and written, respectively.
Sat - Saturation. This the number of errors/second seen for the interface
an indicator the interface may be approaching saturation. This statistic is combined from a number of kernel statistics. It is recommended to use the ‘-x’ option to see more individual statistics (those mentioned below) when attempting to diagnose a network issue.
IErr - Packets received that could not be processed because they contained errors
OErr - Packets that were not successfully transmitted because of errors
Coll - Ethernet collisions during transmit.
NoCP - No-can-puts. This is when an incoming packet can not be put to the process reading the socket. This suggests the local process is unable to process incoming packets in a timely manner.
Defer - Defer Transmits. Packets without collisions where first transmit attempt was delayed because the medium was busy.
Reset - tcpEstabResets. The number of times TCP connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state.
AttF - tcpAttemptFails - The number of times that TCP connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state, plus the number of times TCP connections have made a direct transition to the LISTEN state from the SYN-RCVD state.
%ReTX - Percentage of TCP segments retransmitted - that is, the number of TCP segments transmitted containing one or more previously transmitted octets.
InConn - tcpPassiveOpens - The number of times that TCP connections have made a direct transition to the SYN-RCVD state from the LISTEN state.
OutCon - tcpActiveOpens - The number of times that TCP connections have made a direct transition to the SYN-SENT state from the CLOSED state.
Drops - tcpHalfOpenDrop + tcpListenDrop + tcpListenDropQ0. tcpListenDrop and tcpListenDropQ0 - Number of connections dropped from the completed connection queue and incomplete connection queue, respectively. tcpHalfOpenDrops - Number of connections dropped after the initial SYN packet was received.
Note: iwconfig is legacy (wireless-tools). Prefer iw for modern drivers, e.g., iw dev, iw dev wlo1 link. Requires: wireless-tools. Modern alternative: iw.
1 2 3 4 5 6 7 8
wlo1 IEEE 802.11 ESSID:"NETGEAR97" Mode:Managed Frequency:2.462 GHz Access Point: C4:04:15:58:60:C7 Bit Rate=72.2 Mb/s Tx-Power=20 dBm Retry short limit:7 RTS thr=2347 B Fragment thr:off Power Management:off Link Quality=70/70 Signal level=-32 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0 Invalid misc:22932 Missed beacon:0
44. brctl
Compat: Legacy; prefer ip link and bridge; Requires: bridge-utils.
brctl is used to set up, maintain, and inspect the ethernet bridge configuration in the linux kernel. Legacy: prefer ip link add name br0 type bridge and bridge (iproute2) tooling. Requires: bridge-utils.
Compat: Linux; May be restricted by kernel.dmesg_restrict; Requires: util-linux.
dmesg --level=<LEVEL> where <LEVEL> is:
emerg - system is unusable.
alert - action must be taken immediately.
crit - critical conditions.
err - error conditions.
warn - warning conditions.
notice - normal but significant condition.
info - informational.
debug - debug-level messages.
dmesg -k: print kernel messages
dmesg -f=<FACILITY> where <FACILITY> is:
kern: Kernel messages.
user: User-level messages.
mail: Mail system.
daemon: System daemons.
auth: Security/authorization messages.
syslog: Internal syslogd messages.
lpr: Line printer subsystem.
news: Network news subsystem.
dmesg -T: human readable timestamps
12. lsmod
Compat: Linux; Lists modules without root; Requires: kmod.
Show loaded kernel modules and sizes/dependencies.
Quick peek: lsmod | head
Module info (version, params): modinfo <module>
13. modprobe
Compat: Linux; Root required; Caution: can destabilize systems; Requires: kmod.
Add or remove modules from the Linux kernel. - Load: modprobe <module>; with params: modprobe <module> key=value - Unload: modprobe -r <module> (fails if in use) - Caution: loading/unloading modules can destabilize systems; prefer persistent config and ensure module compatibility.
Disk & Filesystems
Cheat Card - Space/inodes: df -h and df -i; biggest dirs: du -xhd1 /path | sort -h - IO saturation: iostat -xz 1; per-proc IO: pidstat -d 1, iotop -oPa - Devices/FS: lsblk -o NAME,TYPE,SIZE,ROTA,MOUNTPOINT,MODEL; mounts: findmnt - Mount ops: mount --bind olddir newdir; remount ro: mount -o remount,ro /mnt
Inventory and health - Device tree: lsblk -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,MODEL - Identify filesystem UUID/TYPE: blkid - SMART check (if supported): smartctl -H /dev/sdX and smartctl -a /dev/sdX (Requires: smartmontools) - NVMe info: nvme list; nvme smart-log /dev/nvme0 (Requires: nvme-cli)
Notes - iostat quick view (Requires: sysstat): iostat -xz 1 (watch await, %util, r/s, w/s) - findmnt: show mount hierarchy or lookup by target: findmnt /mount/point
adds or removes modules from the Linux Kernel
Caution: loading/unloading modules can destabilize systems; prefer persistent config and ensure module compatibility.
14. dd (DANGER: DESTRUCTIVE — READ FIRST)
Compat: Linux; Root required for raw devices; Highly destructive when writing; Requires: coreutils.
Danger: dd will overwrite data with no confirmation. Double-check devices (e.g., /dev/sdX) and consider read-only or safer alternatives first. Use lsblk, blkid to verify targets.
Safer tips: for copies, consider pv to visualize throughput; for imaging, dcfldd; for testing, prefer non-destructive reads.
# Requires: jq — show high-priority messages from journald journalctl -o json | jq -r 'select(.PRIORITY<=3) | .MESSAGE'
Keys and length: jq 'keys, length' file.json
16. diff
Compat: Linux; Requires: diffutils.
unified diff: diff -u old.txt new.txt
recursive dirs: diff -ruN dir_old dir_new
ignore whitespace changes: diff -u -w old new
handle CRLF: diff -u --strip-trailing-cr a b
color (if supported): diff --color=auto -u a b
apply a patch: patch -p1 < change.diff
17. uname
Compat: Linux; Requires: coreutils.
get all details about the computer
18. sync/fsync
Compat: Linux; sync is user command; fsync is a syscall.
fsync is a syscall that flushes a file’s in-memory data and metadata to storage. From the shell, use sync (flush all dirty data) or syncfs (flush a filesystem) when available.
Caution: avoid running fsck on a mounted filesystem (except with specific fs support); prefer read-only mounts or maintenance windows.
Extended notes - ext* specifics: e2fsck checks ext2/3/4; use -f to force, -n for read-only, -p for preen (auto-fix safe issues). Requires: e2fsprogs. - Bad blocks (DANGER): badblocks scans devices for bad sectors; write-mode is destructive. Prefer read-only first.
top -O: output fields: print all available sort-attributes
top -p pid1,pid2,...: monitor only these PIDs
top -1: show per-CPU stats
28. vmstat
Compat: Linux; Requires: procps.
Useful to get so/si information
Report virtual memory statistics
vmstat -a: number active/inactive memory
vmstat --stats: various statistics
Interpretation tips - r runnable > number of CPUs indicates run-queue contention. - b blocked processes (often IO wait); correlate with %wa in top/mpstat. - si/so swap in/out: sustained non-zero values indicate memory pressure. - Use vmstat 1 for near-real-time view.
29. strace
Compat: Linux; May be restricted by ptrace scope; Requires: strace.
Trace system calls and signals. - Attach to a PID: strace -ttT -p <pid> -f -e trace=network,file,fsync,clock,nanosleep - Run a program under strace: strace -o strace.log -s 200 -vv -f -ttT your_cmd --arg - Syscall time summary: strace -c -p <pid> - Filter a path: strace -ttT -e trace=file -P /etc/resolv.conf -p <pid> - Notes: -f follows forks; -ttT adds timestamps and syscall durations; -s increases string size. - trace system calls and signals
30. slabtop
Compat: Linux; Requires: procps.
slabtop: display kernel slab cache information in real time
Sort by size: slabtop -s c; one-shot: slabtop -o
31. uptime
Compat: Linux; Requires: procps.
information about how long the system has been up, and load averages
32. htop
Compat: Linux; Requires: htop package.
like top, but prettier
33. ps
Compat: Linux; Requires: procps.
Cheat Card - Top CPU: ps -eo pid,ppid,user,%cpu,%mem,cmd --sort=-%cpu | head - Top RSS: ps -eo pid,user,rss,cmd --sort=-rss | head - Tree view: ps -ejH (or ps axjf) - By command: ps -C nginx -o pid,ppid,cmd,%mem,%cpu - Threads of a PID: ps -Lp <pid> -o pid,tid,pcpu,comm
ps aux: show all processes
ps axjf - print process tree
ps a - Lift the BSD-style “only yourself” restriction
ps -A - select all processes
ps -d - select all processes except session leaders
ps g - select all processes including session leaders
ps Ta - all process associated with this terminal
ps r - restrict to running processes
ps --pid pidlist - restrict to pidlist processes
ps -s|--sid - select by session ID
ps t ttylist - select by TTY list
ps U|-U - select by effective user-id
ps s - display signals
ps f - ASCII art process hierarchy
ps ax -o rss,pid,user,pcpu,command --sort -%cpu: sort by %cpu
ps ax -o rss,pid,user,pcpu,command --sort -rss: sort by rss
process states: - D - uninterruptible sleep (usually IO) - I - Idle kernel thread - R - running or runnable (on run queue) - S - interruptible sleep (waiting for an event to complete) - T - stopped by job control signal - t - stopped by debugger during the tracing - W - paging (not valid since the 2.6.xx kernel) - X - dead (should never be seen) - Z - defunct (“zombie”) process, terminated but not reaped by its parent
see STANDARD FORMAT SPECIFIERS in man ps
CPU
Cheat Card - CPU saturation: mpstat -P ALL 1 (sys/iowait/irq/soft) - Per-core view in top: top -1; over time per PID: pidstat -u 1 -p <pid> - Interrupt spikes: mpstat -I CPU 1
34. mpstat
Compat: Linux; Requires: sysstat.
The mpstat command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. Requires: sysstat.
Interpretation tips - High %iowait: CPUs idle while waiting on disk IO (check iostat). - High %irq/%soft: heavy interrupts/softirqs (often network or storage). - High %steal: hypervisor stealing time (noisy neighbor in a VM). - Compare per-core: hotspots can be isolated to specific cores (affinity).
CPU: Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
%usr: Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice: Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%sys: Show the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include time spent servicing hardware and software interrupts.
%iowait: Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%irq: Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.
%soft: Show the percentage of time spent by the CPU or CPUs to service software interrupts.
%steal: Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
%guest: Show the percentage of time spent by the CPU or CPUs to run a virtual processor.
%gnice: Show the percentage of time spent by the CPU or CPUs to run a niced guest.
used - Used memory (calculated as total - free - buffers - cache)
free - Unused memory (MemFree and SwapFree in /proc/meminfo)
shared - Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)
buffers - Memory used by kernel buffers (Buffers in /proc/meminfo)
cache - Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
buff/cache - Sum of buffers and cache
available - Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)
free -l: show low-high memory breakdown
free --wide: show free memory stats
Interpretation tips - available approximates memory free for new apps without swapping; don’t confuse free with usable memory. - High buff/cache is normal; it’s the page cache and reclaimable slabs.
Examples - Human-readable snapshot: free -h --wide - Example output:
1 2 3
total used free shared buff/cache available Mem: 31Gi 2.1Gi 22Gi 312Mi 7.2Gi 28Gi Swap: 8Gi 0B 8Gi
36. sar
Compat: Linux; Requires: sysstat; history needs sadc enabled.
Cheat Card - CPU load/queue: sar -q 1 5; memory: sar -r 1 5 - IO bw/ops: sar -b 1 5; per-device: sar -d 1 5 (watch await, %util) - Network: sar -n DEV 1 5; TCP: sar -n TCP,ETCP 1 5 - Paging: sar -B 1 5 (pgsteal, pgscan, majflt/s)
Requires: sysstat (includes pidstat).
Field reference (click to expand)
sar -B: report paging stats
gpgin/s - Total number of kilobytes the system paged in from disk per second.
pgpgout/s - Total number of kilobytes the system paged out to disk per second.
fault/s - Number of page faults (major + minor) made by the system per second. This is not a count of page faults that generate I/O, because some page faults can be resolved without I/O.
majflt/s - Number of major faults the system has made per second, those which have required loading a memory page from disk.
pgfree/s - Number of pages placed on the free list by the system per second.
pgscank/s - Number of pages scanned by the kswapd daemon per second.
pgscand/s - Number of pages scanned directly per second.
pgsteal/s - Number of pages the system has reclaimed from cache (pagecache and swapcache) per second to satisfy its memory demands.
%vmeff - Calculated as pgsteal / pgscan, this is a metric of the efficiency of page reclaim. If it is near 100% then almost every page coming off the tail of the inactive list is being reaped. If it gets too low (e.g. less than 30%) then the virtual memory is having some difficulty. This field is displayed as zero if no pages have been scanned during the interval of time.
sar -b: Report I/O and transfer rate statistics.
tps - Total number of transfers per second that were issued to physical devices. A transfer is an I/O request to a physical device. Multiple logical requests can be combined into a single I/O request to the device. A transfer is of indeterminate size.
rtps - Total number of read requests per second issued to physical devices.
wtps - Total number of write requests per second issued to physical devices.
bread/s - Total amount of data read from the devices in blocks per second. Blocks are equivalent to sectors and therefore have a size of 512 bytes.
bwrtn/s - Total amount of data written to devices in blocks per second.
sar -d: report activity for each block device
tps - Total number of transfers per second that were issued to physical devices. A transfer is an I/O request to a physical device. Multiple logical requests can be combined into a single I/O request to the device. A transfer is of indeterminate size.
rkB/s - Number of kilobytes read from the device per second.
wkB/s - Number of kilobytes written to the device per second.
areq-sz - The average size (in kilobytes) of the I/O requests that were issued to the device. Note: In previous versions, this field was known as avgrq-sz and was expressed in sectors.
aqu-sz - The average queue length of the requests that were issued to the device. Note: In previous versions, this field was known as avgqu-sz.
await - The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
svctm - The average service time (in milliseconds) for I/O requests that were issued to the device. Warning! Do not trust this field any more. This field will be removed in a future sysstat version.
%util - Percentage of elapsed time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100% for devices serving requests serially. But for devices serving requests in parallel, such as RAID arrays and modern SSDs, this number does not reflect their performance limits.
sar -F: display stats. for currently mounted FSs:
MBfsfree - Total amount of free space in megabytes (including space available only to privileged user).
MBfsused - Total amount of space used in megabytes.
%fsused - Percentage of filesystem space used, as seen by a privileged user.
%ufsused - Percentage of filesystem space used, as seen by an unprivileged user.
Ifree - Total number of free file nodes in filesystem.
Iused - Total number of file nodes used in filesystem.
%Iused - Percentage of file nodes used in filesystem.
sar -m: power management statistics:
MHz - Instantaneous CPU clock frequency in MHz.
With the FAN keyword, statistics about fans speed are reported. The following values are displayed:
rpm - Fan speed expressed in revolutions per minute.
drpm - This field is calculated as the difference between current fan speed (rpm) and its low limit (fan_min).
DEVICE - Sensor device name.
With the FREQ keyword, statistics about CPU clock frequency are reported. The following value is displayed:
wghMHz - Weighted average CPU clock frequency in MHz. Note that the cpufreq-stats driver must be compiled in the kernel for this option to work.
With the IN keyword, statistics about voltage inputs are reported. The following values are displayed:
inV - Voltage input expressed in Volts.
%in - Relative input value. A value of 100% means that voltage input has reached its high limit (in_max) whereas a value of 0% means that it has reached its low limit (in_min).
DEVICE - Sensor device name.
With the USB keyword, the sar command takes a snapshot of all the USB devices currently plugged into the system. At the end of the report, sar will display a summary of all those USB devices. The following values are displayed:
BUS - Root hub number of the USB device.
idvendor - Vendor ID number (assigned by USB organization).
idprod - Product ID number (assigned by Manufacturer).
maxpower - Maximum power consumption of the device (expressed in mA).
manufact - Manufacturer name.
product - Product name.
sar -n DEV:
IFACE - Name of the network interface for which statistics are reported.
rxpck/s - Total number of packets received per second.
txpck/s - Total number of packets transmitted per second.
rxkB/s - Total number of kilobytes received per second.
txkB/s - Total number of kilobytes transmitted per second.
rxcmp/s - Number of compressed packets received per second (for cslip etc.).
txcmp/s - Number of compressed packets transmitted per second.
rxmcst/s - Number of multicast packets received per second.
%ifutil - Utilization percentage of the network interface. For half-duplex interfaces, utilization is calculated using the sum of rxkB/s and txkB/s as a percentage of the interface speed. For full-duplex, this is the greater of rxkB/S or txkB/s.
sar -n EDEV:
IFACE - Name of the network interface for which statistics are reported.
rxerr/s - Total number of bad packets received per second.
txerr/s - Total number of errors that happened per second while transmitting packets.
coll/s - Number of collisions that happened per second while transmitting packets.
rxdrop/s - Number of received packets dropped per second because of a lack of space in linux buffers.
txdrop/s - Number of transmitted packets dropped per second because of a lack of space in linux buffers.
txcarr/s - Number of carrier-errors that happened per second while transmitting packets.
rxfram/s - Number of frame alignment errors that happened per second on received packets.
rxfifo/s - Number of FIFO overrun errors that happened per second on received packets.
txfifo/s - Number of FIFO overrun errors that happened per second on transmitted packets.
sar -n ICMP:
imsg/s - The total number of ICMP messages which the entity received per second [icmpInMsgs]. Note that this counter includes all those counted by ierr/s.
omsg/s - The total number of ICMP messages which this entity attempted to send per second [icmpOutMsgs]. Note that this counter includes all those counted by oerr/s.
iech/s - The number of ICMP Echo (request) messages received per second [icmpInEchos].
iechr/s - The number of ICMP Echo Reply messages received per second [icmpInEchoReps].
oech/s - The number of ICMP Echo (request) messages sent per second [icmpOutEchos].
oechr/s - The number of ICMP Echo Reply messages sent per second [icmpOutEchoReps].
itm/s - The number of ICMP Timestamp (request) messages received per second [icmpInTimestamps].
itmr/s - The number of ICMP Timestamp Reply messages received per second [icmpInTimestampReps].
otm/s - The number of ICMP Timestamp (request) messages sent per second [icmpOutTimestamps].
otmr/s - The number of ICMP Timestamp Reply messages sent per second [icmpOutTimestampReps].
iadrmk/s - The number of ICMP Address Mask Request messages received per second [icmpInAddrMasks].
oadrmk/s - The number of ICMP Address Mask Request messages sent per second [icmpOutAddrMasks].
oadrmkr/s - The number of ICMP Address Mask Reply messages sent per second [icmpOutAddrMaskReps].
sar -n EICMP: Extended ICMP stats (errors, dest unreachable, time exceeded). Focus on spikes in ierr/s and oerr/s, and patterns in unreachable/time- exceeded when debugging path issues.
sar -n EIP: Extended IPv4 stats (header errors, addr errors, discards, no routes, reassembly, fragment fails). Use to spot header errors and routing/ no-route conditions.
sar -n IP6: IPv6 per-protocol counters (receive/deliver/forward, multicast, fragmentation). Check for anomalies similar to IPv4.
sar -n EIP6: Extended IPv6 errors and routing stats (header/addr errors, discards, no routes, reassembly/frag). Useful for IPv6-specific troubleshooting.
sar -n SOCK:
totsck - Total number of sockets used by the system.
tcpsck - TCP sockets in use; tcp-tw - TIME_WAIT sockets.
sar -n SOFT:
total/s - The total number of network frames processed per second.
dropd/s - The total number of network frames dropped per second because there was no room on the processing queue.
squeezd/s - The number of times the softirq handler function terminated per second because its budget was consumed or the time limit was reached, but more work could have been done.
rx_rps/s - The number of times the CPU has been woken up per second to process packets via an inter-processor interrupt.
flw_lim/s - The number of times the flow limit has been reached per second. Flow limiting is an optional RPS feature that can be used to limit the number of packets queued to the backlog for each flow to a certain amount. This can help ensure that smaller flows are processed even though much larger flows are pushing packets in.
sar -n TCP:
active/s - The number of times TCP connections have made a direct transition to the SYN-SENT state from the CLOSED state per second [tcpActiveOpens].
passive/s - The number of times TCP connections have made a direct transition to the SYN-RCVD state from the LISTEN state per second [tcpPassiveOpens].
iseg/s - The total number of segments received per second, including those received in error [tcpInSegs]. This count includes segments received on currently established connections.
oseg/s - The total number of segments sent per second, including those on current connections but excluding those containing only retransmitted octets [tcpOutSegs].
sar -n ETCP:
atmptf/s - The number of times per second TCP connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state, plus the number of times per second TCP connections have made a direct transition to the LISTEN state from the SYN-RCVD state [tcpAttemptFails].
estres/s - The number of times per second TCP connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state [tcpEstabResets].
retrans/s - The total number of segments retransmitted per second - that is, the number of TCP segments transmitted containing one or more previously transmitted octets [tcpRetransSegs].
isegerr/s - The total number of segments received in error (e.g., bad TCP checksums) per second [tcpInErrs].
orsts/s - The number of TCP segments sent per second containing the RST flag [tcpOutRsts].
sar -n UDP:
idgm/s - The total number of UDP datagrams delivered per second to UDP users [udpInDatagrams].
odgm/s - The total number of UDP datagrams sent per second from this entity [udpOutDatagrams].
noport/s - The total number of received UDP datagrams per second for which there was no application at the destination port [udpNoPorts].
idgmerr/s - The number of received UDP datagrams per second that could not be delivered for reasons other than the lack of an application at the destination port [udpInErrors].
sar -n UDP6:
idgm6/s - The total number of UDP datagrams delivered per second to UDP users [udpInDatagrams].
odgm6/s - The total number of UDP datagrams sent per second from this entity [udpOutDatagrams].
noport6/s - The total number of received UDP datagrams per second for which there was no application at the destination port [udpNoPorts].
idgmer6/s - The number of received UDP datagrams per second that could not be delivered for reasons other than the lack of an application at the destination port [udpInErrors].
sar -q:
runq-sz - Run queue length (number of tasks waiting for run time).
plist-sz - Number of tasks in the task list.
ldavg-1 - System load average for the last minute. The load average is calculated as the average number of runnable or running tasks (R state), and the number of tasks in uninterruptible sleep (D state) over the specified interval.
ldavg-5 - System load average for the past 5 minutes.
ldavg-15 - System load average for the past 15 minutes.
blocked - Number of tasks currently blocked, waiting for I/O to complete.
sar -r:
kbmemfree - Amount of free memory available in kilobytes.
kbavail - Estimate of how much memory in kilobytes is available for starting new applications, without swapping. The estimate takes into account that the system needs some page cache to function well, and that not all reclaimable memory slabs will be reclaimable, due to items being in use. The impact of those factors will vary from system to system.
kbmemused - Amount of used memory in kilobytes (calculated as total installed memory - kbmemfree - kbbuffers - kbcached - kbslab).
%memused - Percentage of used memory.
kbbuffers - Amount of memory used as buffers by the kernel in kilobytes.
kbcached - Amount of memory used to cache data by the kernel in kilobytes.
kbcommit - Amount of memory in kilobytes needed for current workload. This is an estimate of how much RAM/swap is needed to guarantee that there never is out of memory.
%commit - Percentage of memory needed for current workload in relation to the total amount of memory (RAM+swap). This number may be greater than 100% because the kernel usually overcommits memory.
kbactive - Amount of active memory in kilobytes (memory that has been used more recently and usually not reclaimed unless absolutely necessary).
kbinact - Amount of inactive memory in kilobytes (memory which has been less recently used. It is more eligible to be reclaimed for other purposes).
kbdirty - Amount of memory in kilobytes waiting to get written back to the disk.
kbanonpg - Amount of non-file backed pages in kilobytes mapped into userspace page tables.
kbslab - Amount of memory in kilobytes used by the kernel to cache data structures for its own use.
kbkstack - Amount of memory in kilobytes used for kernel stack space.
kbpgtbl - Amount of memory in kilobytes dedicated to the lowest level of page tables.
kbvmused - Amount of memory in kilobytes of used virtual address space.
sar -S:
kbswpfree - Amount of free swap space in kilobytes.
kbswpused - Amount of used swap space in kilobytes.
%swpused - Percentage of used swap space.
kbswpcad - Amount of cached swap memory in kilobytes. This is memory that once was swapped out, is swapped back in but still also is in the swap area (if memory is needed it doesn’t need to be swapped out again because it is already in the swap area. This saves I/O).
%swpcad - Percentage of cached swap memory in relation to the amount of used swap space.
sar -u:
%user - Percentage of CPU utilization that occurred while executing at the user level (application). Note that this field includes time spent running virtual processors.
%usr - Percentage of CPU utilization that occurred while executing at the user level (application). Note that this field does NOT include time spent running virtual processors.
%nice - Percentage of CPU utilization that occurred while executing at the user level with nice priority.
%system - Percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this field includes time spent servicing hardware and software interrupts.
%sys - Percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this field does NOT include time spent servicing hardware or software interrupts.
%iowait - Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%steal - Percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
%irq - Percentage of time spent by the CPU or CPUs to service hardware interrupts.
%soft - Percentage of time spent by the CPU or CPUs to service software interrupts.
%guest - Percentage of time spent by the CPU or CPUs to run a virtual processor.
%gnice - Percentage of time spent by the CPU or CPUs to run a niced guest.
%idle - Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
sar -v:
dentunusd - Number of unused cache entries in the directory cache.
file-nr - Number of file handles used by the system.
inode-nr - Number of inode handlers used by the system.
pty-nr - Number of pseudo-terminals used by the system.
sar -W: Report swapping statistics. The following values are displayed:
pswpin/s - Total number of swap pages the system brought in per second.
pswpout/s - Total number of swap pages the system brought out per second.
sar -w: Report task creation and system switching activity.
proc/s - Tasks created per second; cswch/s - context switches per second.
sar -y: Report TTY devices activity. The following values are displayed:
rcvin/s - Number of receive interrupts per second for current serial line. Serial line number is given in the TTY column.
xmtin/s - Number of transmit interrupts per second for current serial line.
framerr/s - Number of frame errors per second for current serial line.
prtyerr/s - Number of parity errors per second for current serial line.
brk/s - Number of breaks per second for current serial line.
ovrun/s - Number of overrun errors per second for current serial line.
45. pidstat
Compat: Linux; Requires: sysstat.
monitor individual tasks currently being managed Requires: sysstat.
blktrace is a block layer IO tracing mechanism which provides detailed information about request queue operations up to user space. There are three major components: a kernel component, a utility to record the i/o trace information for the kernel to user space, and utilities to analyse and view the trace information.
1 2
# Trace block I/O on /dev/sda and parse sudo blktrace -d /dev/sda -o - | blkparse -i -
Compat: Linux; Wrapper script from blktrace; Root required.
The btrace script provides a quick and easy way to do live tracing of block devices. It calls blktrace on the specified devices and pipes the output through blkparse for formatting. See blktrace (8) for more in-depth information about how blktrace works.
btrace /dev/sda Requires: blktrace.
54. tr
Compat: Linux; Requires: coreutils.
Translate, squeeze, and/or delete characters from standard input, writing to standard output.
# List, inspect, and logs via crictl crictl ps -a crictl inspect <id> crictl logs <id>
Notes - Without runtime CLIs, use nsenter by PID from ps/systemctl. - Requires: docker or podman for Docker-like commands; kubectl; crictl for containerd/CRI.
Incident Playbooks
High CPU
1 2 3 4 5 6 7 8
# Top CPU processes and hot threads ps -eo pid,ppid,user,%cpu,%mem,cmd --sort=-%cpu | head top -H ps -Lp <pid> -o pid,tid,pcpu,comm
# Per-process CPU over time; optional perf if available pidstat -u 1 -p <pid> perf top # if installed