Quick take: sudo lshw -short gives a compact one-line-per-device hardware summary. Use -class disk, -class network, or -class memory to filter by device type. Generate an HTML report with sudo lshw -html > report.html.
What Is lshw in Linux?
lshw (List Hardware) is a comprehensive hardware information tool that reads system hardware details from multiple sources: /proc, /sys, DMI/BIOS tables, and direct hardware probing. It shows model names, firmware versions, bus speeds, driver names, and logical device names — all in one command.
It is the go-to tool when you need to document server specifications for a client, verify hardware before a firmware upgrade, or diagnose driver binding issues for a newly added device.
Install lshw
# Ubuntu / Debian
sudo apt install lshw
# RHEL / CentOS / Rocky
sudo dnf install lshw
# Verify
lshw -versionSyntax
sudo lshw [OPTIONS]Root privileges are required for complete hardware data. Without sudo, many device entries show as "UNCLAIMED" or display incomplete information.
Common Options
| Option | Description |
|---|---|
| -short | Compact tabular view — one line per device |
| -html | Output as an HTML page |
| -json | Output as JSON (pipe to jq for processing) |
| -xml | Output as XML |
| -class CLASS | Filter by device class (disk, network, memory, processor, etc.) |
| -C CLASS | Short form of -class |
| -businfo | Show bus information (PCI bus IDs, USB ports) |
| -sanitize | Remove sensitive data (serial numbers) before sharing output |
| -quiet | Suppress progress messages |
Practical Examples
# Quick summary — best starting point
sudo lshw -short
# Filter to memory modules only
sudo lshw -class memory -short
# Filter to disks
sudo lshw -class disk -short
# Filter to network interfaces
sudo lshw -class network -short
# Filter to CPU
sudo lshw -class processor
# Show PCI bus info for all devices
sudo lshw -businfo
# JSON output — pipe to jq
sudo lshw -json | jq '.children[] | select(.class == "storage")'
# Safe output for sharing (removes serial numbers)
sudo lshw -short -sanitizeSample lshw -short output:
H/W path Device Class Description
====================================================
system PowerEdge R640
/0 bus 0CXJM3
/0/0 memory 64GiB System Memory
/0/0/0 memory 32GiB DIMM DDR4 Synchronous 2666 MHz
/0/1 processor Intel Xeon Silver 4210R
/0/100/1f.2 /dev/sda disk 240GB SATA SSD
/0/100/1f.2/0 volume 223GiB EXT4 volume
/1 eno1 network Ethernet interface 10GbEGenerate an HTML Report
For client documentation or asset management, lshw can generate a formatted HTML page:
# Generate and save HTML report
sudo lshw -html > /tmp/hardware_report.html
# Sanitize (remove serial numbers) then generate
sudo lshw -html -sanitize > /tmp/hardware_report_safe.html
# View in browser (on a desktop system)
xdg-open /tmp/hardware_report.html
# Transfer to your laptop for viewing
scp server:/tmp/hardware_report.html ~/Downloads/The HTML report is well-formatted and includes color-coded device classes — useful for sending to procurement teams or storing in a server inventory system.
Related Hardware Commands
lshw covers the full hardware picture, but these focused tools complement it:
lscpu— CPU details, cores, NUMA topology, flagslsblk— Block device tree (disks, partitions, LVM volumes)lspci— PCI bus devices (GPUs, network cards, RAID controllers)lsusb— USB devices and their bus addressesdmidecode— Raw BIOS/UEFI DMI table data (memory speed, firmware version)inxi -Fxz— Another comprehensive hardware overview tool
# CPU details
lscpu
# Disk and partition tree
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT
# PCI devices
lspci -v
# Memory DIMM details from DMI
sudo dmidecode -t memory | grep -E "Size|Speed|Manufacturer|Part"Processing lshw JSON Output with jq
The -json output is the most useful for automation — you can pipe it to jq to extract exactly what you need from any device class.
# Extract all disk device names and sizes
sudo lshw -json -class disk | jq '.[] | {name: .logicalname, size: .size, description: .description}'
# Extract RAM details — manufacturer, part number, speed
sudo lshw -json -class memory | jq '.[] | .children[]? | {product: .product, size: .size, clock: .clock}'
# Get network interface MAC addresses and driver
sudo lshw -json -class network | jq '.[] | {name: .logicalname, mac: .serial, driver: .configuration.driver}'
# Build a hardware inventory script
sudo lshw -json | jq '{
hostname: .id,
cpu: (.children[].children[]? | select(.class == "processor") | .product),
memory_gb: ([.children[].children[]? | select(.class == "memory") | .size?] | add / 1073741824),
disks: [.. | objects | select(.class == "disk") | .logicalname]
}'
lshw vs Alternative Hardware Tools
| Tool | Best for | Install |
|---|---|---|
| lshw | Full system inventory, structured output (JSON/HTML/XML) | apt install lshw |
| lscpu | CPU details — cores, cache, NUMA topology | Built into util-linux |
| lsblk | Block device tree, mount points, partition sizes | Built into util-linux |
| lspci | PCI bus devices — GPU, RAID controller, NIC cards | apt install pciutils |
| lsusb | USB device enumeration | apt install usbutils |
| dmidecode | BIOS/UEFI information, SMBIOS tables, memory slot details | apt install dmidecode |
| inxi | Human-readable system summary for forum posts | apt install inxi |
Server Inventory Script
This script documents a server's hardware specs into a text file — useful before a migration or for client handover documentation:
#!/bin/bash
HOSTNAME=$(hostname -f)
DATE=$(date +%Y-%m-%d)
OUTPUT="/tmp/${HOSTNAME}_hardware_${DATE}.txt"
{
echo "=== Hardware Inventory: $HOSTNAME ($DATE) ==="
echo ""
echo "--- CPU ---"
lscpu | grep -E "Model name|Socket|Core|Thread|Architecture"
echo ""
echo "--- Memory ---"
sudo lshw -class memory -short 2>/dev/null
echo ""
echo "--- Disks ---"
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
echo ""
echo "--- Network ---"
sudo lshw -class network -short 2>/dev/null
echo ""
echo "--- Full JSON ---"
sudo lshw -json -sanitize 2>/dev/null
} > "$OUTPUT"
echo "Inventory saved to: $OUTPUT"
Common Errors and Fixes
| Problem | Cause | Fix |
|---|---|---|
| Device shows as UNCLAIMED | Running without root, or no driver loaded for device | Run with sudo; check dmesg | grep firmware for missing firmware |
| Missing memory details (size shows 0) | Virtualized environment (VMs don't expose SMBIOS memory info) | Use free -h for memory; dmidecode for physical servers |
| lshw: command not found | Not installed | sudo apt install lshw |
| HTML report opens blank | Browser security policy blocks local file | Transfer to desktop with scp or serve with python3 -m http.server |
Reference: lshw man page — linux.die.net. Tested on Ubuntu 22.04 LTS (bare metal Dell PowerEdge) and Ubuntu 24.04 LTS (AWS EC2 t3.medium).
Final Thoughts
lshw is the most complete single-command hardware inventory tool available on Linux. Start with sudo lshw -short for a quick overview and add -class filtering to drill into specific subsystems. For documentation and client reports, the HTML output format is professional enough to send directly without formatting.
FAQ: lshw Command in Linux
How do I install lshw on Ubuntu?+
Run sudo apt install lshw. On RHEL/CentOS, use sudo dnf install lshw. After install, run sudo lshw -short for a quick hardware overview.
Why does lshw need to be run with sudo?+
Without root privileges, lshw cannot read all hardware registers and will show incomplete or unknown data for many devices. Always run sudo lshw for complete results.
How do I get a summary hardware list instead of full details?+
Use sudo lshw -short for a compact tabular view with one line per device, showing bus path, device name, class, and description. This is the most readable format for a quick inventory.
How do I generate an HTML hardware report with lshw?+
Run sudo lshw -html > hardware_report.html. This creates a formatted HTML page you can open in a browser and share with clients or colleagues as a server inventory document.
How do I filter lshw to show only network cards?+
Use sudo lshw -class network. Other useful classes include memory, disk, display, processor, and storage. Combine with -short for concise output: sudo lshw -class disk -short.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support