Master Linux System Inspection: lsmod, lsof, lspci & lsscsi Explained with Real Examples
This guide introduces four essential Linux commands—lsmod, lsof, lspci, and lsscsi—detailing their purpose, syntax, useful options, and practical output examples, helping system administrators quickly diagnose kernel modules, open files, PCI devices, and SCSI devices.
1. lsmod command
The lsmod command displays information about kernel modules currently loaded into the Linux kernel, listing each module’s name, size, usage count, and dependent modules.
Syntax
lsmodExample
The output columns represent:
Column 1: module name
Column 2: module size
Column 3: number of dependent modules
Column 4: list of dependent modules
Typical usage includes filtering with lsmod | grep -i ext3 to check for specific modules.
2. lsof command
The lsof command lists open files, the processes that opened them, and associated network ports (TCP/UDP). It can also help recover deleted files and requires root privileges to access kernel memory.
Syntax
lsof(选项)Options
-a: list processes with open files
-c<process_name>: list files opened by the specified process
-g: display GID details
-d<file_descriptor>: show processes using the given file descriptor
+d<directory>: list files opened under the directory
+D<directory>: recursively list files opened under the directory
-n: list NFS files
-i<criteria>: filter processes by protocol, port, or IP
-p<pid>: list files opened by the specified PID
-u: display UID details
-h: show help
-v: show version
Example
Key columns include COMMAND (process name), PID, PPID, USER, PGID, and FD (file descriptor).
3. lspci command
The lspci command lists all PCI bus devices and their details on the host.
Syntax
lspci(选项)Options
-n: display numeric vendor and device codes
-t: show devices in a tree hierarchy
-b: bus-centric view
-d: filter by specific vendor/device
-s: show devices on a given bus/slot
-i: use a custom PCI ID list file
-m: machine‑readable output
Example
4. lsscsi command
The lsscsi command displays information about SCSI devices attached to the system.
Parameters
-s: show capacity size
-c: display full information
-d: show major/minor device numbers
-g: show corresponding sg device name
-H: list host controllers (options -Hl, -Hlv)
-l: display related attributes (options -ll, -lll, -L)
-v: show device attribute directories
-x: display LUN in hexadecimal
-p: output DIF/DIX protection types
-P: output valid protection mode information
-i: show udev‑related attributes
-w: display WWN
Example
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
