Display System Hardware Information with lshw Command

Learn how to use the lshw command to extract detailed hardware information on Linux systems. Complete guide with installation and usage examples.

Display System Hardware Information with lshw

Introduction

The lshw (List Hardware) command is a powerful system administration tool for Linux and Unix-like operating systems that provides comprehensive information about the hardware configuration of a system. Unlike other hardware detection utilities that may focus on specific components, lshw offers a complete overview of all hardware components in a hierarchical format, making it an essential tool for system administrators, technical support personnel, and users who need detailed hardware information.

What is lshw

lshw is a small tool that extracts detailed information about the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, and more on DMI-capable x86 or EFI systems and on some PowerPC machines.

The tool gathers information from various sources including: - /proc filesystem - DMI (Desktop Management Interface) tables - SMBIOS (System Management BIOS) - PCI configuration space - USB device tree - SCSI inquiry data - CPU information from /proc/cpuinfo - Memory information from /proc/meminfo

Installation

Ubuntu/Debian Systems

`bash sudo apt update sudo apt install lshw `

Red Hat/CentOS/Fedora Systems

`bash

For RHEL/CentOS 7 and earlier

sudo yum install lshw

For RHEL/CentOS 8+ and Fedora

sudo dnf install lshw `

Arch Linux

`bash sudo pacman -S lshw `

SUSE/openSUSE

`bash sudo zypper install lshw `

Basic Usage and Syntax

The basic syntax of the lshw command is:

`bash lshw [OPTIONS] `

Most lshw operations require root privileges to access all hardware information, so it is typically run with sudo.

Basic Command

`bash sudo lshw `

This command displays a complete hardware inventory in a hierarchical tree format.

Command Options and Parameters

| Option | Long Form | Description | |--------|-----------|-------------| | -html | --html | Generate HTML output | | -xml | --xml | Generate XML output | | -json | --json | Generate JSON output | | -short | --short | Generate short output | | -businfo | --businfo | Show bus information | | -class CLASS | --class=CLASS | Show only specified class of hardware | | -C CLASS | | Shorthand for -class | | -enable TEST | --enable=TEST | Enable specific test | | -disable TEST | --disable=TEST | Disable specific test | | -quiet | --quiet | Don't display status | | -sanitize | --sanitize | Remove sensitive information | | -numeric | --numeric | Show numeric IDs | | -notime | --notime | Exclude timestamps |

Hardware Classes

lshw organizes hardware information into various classes:

| Class | Description | |-------|-------------| | system | Main system board | | bus | System buses (PCI, USB, etc.) | | memory | Memory modules and controllers | | processor | CPU information | | display | Graphics cards and display adapters | | multimedia | Audio and video devices | | network | Network interfaces | | storage | Storage controllers and devices | | disk | Hard drives and storage devices | | volume | Disk partitions and volumes | | generic | Generic devices | | power | Power management devices | | communication | Communication devices | | input | Input devices | | printer | Printing devices |

Detailed Command Examples

Basic Hardware Information

`bash sudo lshw `

This command provides a complete hierarchical view of all system hardware. The output includes detailed information about each component, including manufacturer, model, capabilities, and configuration.

Short Format Output

`bash sudo lshw -short `

Example output: ` H/W path Device Class Description ===================================================== system OptiPlex 7010 /0 bus 0773VV /0/0 memory 64KiB BIOS /0/4 processor Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz /0/4/5 memory 256KiB L1 cache /0/4/6 memory 1MiB L2 cache /0/4/7 memory 6MiB L3 cache /0/8 memory 16GiB System Memory /0/8/0 memory 8GiB DIMM DDR3 Synchronous 1600 MHz /0/8/1 memory 8GiB DIMM DDR3 Synchronous 1600 MHz `

Bus Information Display

`bash sudo lshw -businfo `

This format shows the relationship between hardware components and their bus connections:

` Bus info Device Class Description ==================================================== system OptiPlex 7010 bus 0773VV memory 64KiB BIOS cpu@0 processor Intel(R) Core(TM) i5-3470 CPU memory 256KiB L1 cache memory 1MiB L2 cache memory 6MiB L3 cache pci@0000:00:00.0 bridge 3rd Gen Core processor DRAM Controller pci@0000:00:02.0 display Xeon E3-1200 v2/3rd Gen Core processor Graphics Controller `

Specific Hardware Class Information

`bash sudo lshw -class processor `

This command shows only processor information:

` *-cpu description: CPU product: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz vendor: Intel Corp. physical id: 4 bus info: cpu@0 version: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz serial: To Be Filled By O.E.M slot: SOCKET 0 size: 1600MHz capacity: 4GHz width: 64 bits clock: 100MHz capabilities: x86-64 fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts configuration: cores=4 enabledcores=4 threads=4 `

Memory Information

`bash sudo lshw -class memory `

Network Interfaces

`bash sudo lshw -class network `

Storage Devices

`bash sudo lshw -class storage sudo lshw -class disk `

Output Formats

HTML Output

`bash sudo lshw -html > hardware_report.html `

This generates a formatted HTML report that can be viewed in a web browser, making it easy to share hardware information or create documentation.

XML Output

`bash sudo lshw -xml > hardware_report.xml `

XML output is useful for parsing by other applications or scripts that need to process hardware information programmatically.

JSON Output

`bash sudo lshw -json > hardware_report.json `

JSON format is particularly useful for modern applications and APIs that need to consume hardware information.

Advanced Usage Examples

Multiple Hardware Classes

`bash sudo lshw -class processor -class memory -class network `

Sanitized Output for Security

`bash sudo lshw -sanitize `

The sanitize option removes or obscures sensitive information such as serial numbers, which is useful when sharing hardware information publicly.

Numeric IDs Display

`bash sudo lshw -numeric `

This option shows numeric vendor and device IDs alongside or instead of names, which can be useful for hardware identification and driver development.

Quiet Operation

`bash sudo lshw -quiet -short `

Suppresses status messages and warnings, showing only the hardware information.

Practical Use Cases

System Inventory and Documentation

`bash

Create comprehensive hardware documentation

sudo lshw -html > /var/log/hardware_inventory_$(date +%Y%m%d).html

Generate short format for quick reference

sudo lshw -short > /var/log/hardware_summary.txt `

Hardware Troubleshooting

`bash

Check specific component for troubleshooting

sudo lshw -class network sudo lshw -class storage sudo lshw -class display `

Driver Identification

`bash

Get vendor and device IDs for driver identification

sudo lshw -numeric -class network `

Memory Analysis

`bash

Detailed memory configuration

sudo lshw -class memory | grep -E "(description|size|speed|vendor)" `

Performance Analysis Preparation

`bash

Get CPU specifications for performance tuning

sudo lshw -class processor | grep -E "(product|size|capacity|cores|threads)" `

Understanding lshw Output

Hierarchical Structure

The lshw output follows a hierarchical tree structure where each component is represented with appropriate indentation and connections. The main system is at the root, with subsystems and components branched below.

Key Information Fields

| Field | Description | |-------|-------------| | description | Human-readable description of the component | | product | Product name or model | | vendor | Manufacturer name | | physical id | Physical identifier within parent component | | bus info | Bus location information | | logical name | Linux device name | | version | Hardware version or revision | | serial | Serial number | | size | Current operational size/speed | | capacity | Maximum capacity | | width | Data width (for memory, buses) | | clock | Clock speed | | capabilities | Supported features and capabilities | | configuration | Current configuration parameters | | resources | System resources used (IRQ, memory, I/O ports) |

Comparison with Other Hardware Detection Tools

| Tool | Purpose | Advantages | Disadvantages | |------|---------|------------|---------------| | lshw | Complete hardware inventory | Comprehensive, multiple output formats | Requires root access | | lscpu | CPU information only | Detailed CPU info, no root required | Limited to CPU only | | lsblk | Block devices | Good for storage overview | Limited to block devices | | lspci | PCI devices | Detailed PCI information | Only PCI bus devices | | lsusb | USB devices | USB-specific details | Only USB devices | | dmidecode | DMI/SMBIOS data | Low-level system information | Less user-friendly output |

Scripting and Automation

Bash Script Example

`bash #!/bin/bash

Hardware inventory script

REPORT_DIR="/var/log/hardware_reports" DATE=$(date +%Y%m%d_%H%M%S)

Create report directory if it doesn't exist

mkdir -p "$REPORT_DIR"

Generate various format reports

echo "Generating hardware reports..."

HTML report

sudo lshw -html > "$REPORT_DIR/hardware_report_$DATE.html"

JSON report for programmatic use

sudo lshw -json > "$REPORT_DIR/hardware_report_$DATE.json"

Short summary

sudo lshw -short > "$REPORT_DIR/hardware_summary_$DATE.txt"

Specific component reports

sudo lshw -class processor > "$REPORT_DIR/cpu_info_$DATE.txt" sudo lshw -class memory > "$REPORT_DIR/memory_info_$DATE.txt" sudo lshw -class network > "$REPORT_DIR/network_info_$DATE.txt"

echo "Reports generated in $REPORT_DIR" `

Monitoring Script

`bash #!/bin/bash

Monitor hardware changes

BASELINE="/var/log/hardware_baseline.txt" CURRENT="/tmp/hardware_current.txt"

Generate current hardware snapshot

sudo lshw -short > "$CURRENT"

Compare with baseline if it exists

if [ -f "$BASELINE" ]; then if ! diff -q "$BASELINE" "$CURRENT" > /dev/null; then echo "Hardware configuration has changed!" diff "$BASELINE" "$CURRENT" else echo "No hardware changes detected" fi else echo "Creating baseline hardware configuration" cp "$CURRENT" "$BASELINE" fi `

Security Considerations

Sensitive Information

lshw can reveal sensitive system information including: - Serial numbers - System manufacturer details - Network MAC addresses - Detailed system architecture

Using Sanitize Option

`bash sudo lshw -sanitize -short `

This option helps protect sensitive information when sharing hardware reports.

Access Control

Since lshw requires root privileges to access complete hardware information, ensure proper access controls are in place:

`bash

Create a dedicated user for hardware reporting

sudo useradd -r -s /bin/false hwreport

Allow specific users to run lshw via sudo

echo "username ALL=(root) NOPASSWD: /usr/bin/lshw" >> /etc/sudoers.d/lshw `

Troubleshooting Common Issues

Permission Denied Errors

`bash

Problem: lshw: you should be root to get complete information

Solution: Run with sudo

sudo lshw `

Incomplete Information

Some hardware information may not be available without root privileges: `bash

Limited information

lshw -short

Complete information

sudo lshw -short `

Performance on Large Systems

On systems with extensive hardware, lshw may take time to complete: `bash

Use specific classes to speed up queries

sudo lshw -class processor -class memory `

Best Practices

Regular Hardware Audits

Implement regular hardware inventory collection: `bash

Add to crontab for monthly reports

0 0 1 /usr/bin/sudo /usr/bin/lshw -html > /var/log/monthly_hardware_$(date +\%Y\%m).html `

Documentation Standards

Establish consistent documentation practices: - Use descriptive filenames with timestamps - Include system hostname in reports - Store reports in organized directory structures - Implement retention policies for old reports

Integration with Configuration Management

Integrate lshw with configuration management tools: `bash

Ansible playbook task example

- name: Generate hardware inventory shell: lshw -json register: hardware_info become: yes

- name: Save hardware inventory copy: content: "#" dest: "/var/log/hardware_#.json" `

Conclusion

The lshw command is an indispensable tool for system administrators and technical professionals who need comprehensive hardware information. Its ability to provide detailed, hierarchical hardware inventories in multiple formats makes it suitable for various use cases, from troubleshooting and documentation to automated system management and compliance reporting.

Understanding how to effectively use lshw and its various options enables better system management, more efficient troubleshooting, and comprehensive hardware documentation. Whether used for one-time hardware audits or integrated into automated monitoring systems, lshw provides the detailed hardware visibility necessary for effective system administration.

The tool's flexibility in output formats, combined with its comprehensive hardware detection capabilities, makes it a valuable addition to any system administrator's toolkit. Regular use of lshw helps maintain accurate hardware inventories, supports capacity planning decisions, and provides the detailed information necessary for effective system management and support.

Tags

  • Command Line
  • Linux
  • hardware
  • lshw
  • system-administration

Related Articles

Popular Technical Articles & Tutorials

Explore our comprehensive collection of technical articles, programming tutorials, and IT guides written by industry experts:

Browse all 8+ technical articles | Read our IT blog

Display System Hardware Information with lshw Command