Linux lshw Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux lshw (List Hardware) command to gather detailed information about the hardware components of your system. The lab covers understanding the purpose of the lshw command, exploring various hardware details using the command, and customizing the output to save the information to a file. The lshw command is a powerful tool for troubleshooting hardware-related issues, understanding system capabilities, and more. This lab provides practical examples and step-by-step guidance to help you effectively utilize the lshw command in your Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/BasicFileOperationsGroup -.-> linux/cat("`File Concatenating`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/cat -.-> lab-422779{{"`Linux lshw Command with Practical Examples`"}} linux/sudo -.-> lab-422779{{"`Linux lshw Command with Practical Examples`"}} end

Understand the lshw Command and Its Purpose

In this step, you will learn about the lshw (List Hardware) command and its purpose. The lshw command is a powerful tool in Linux that provides detailed information about the hardware components of your system.

The lshw command can be used to gather information about various hardware components, such as:

  • CPU
  • Memory
  • Motherboard
  • Disk drives
  • Network interfaces
  • USB devices
  • PCI devices
  • and more

To get started, let's run the lshw command in the terminal:

sudo lshw

Example output:

*-core
     description: Motherboard
     product: Virtual Machine
     vendor: Google
     physical id: 0
     version: None
     serial: None
     slot: None
   *-firmware
        description: BIOS
        vendor: Google
        physical id: 0
        version: Google
        date: 04/01/2014
   *-cpu
        description: CPU
        product: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
        vendor: Intel Corp.
        physical id: cpu
        bus info: cpu@0
        version: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
        serial: None
        slot: LGA1151
        size: 3700MHz
        capacity: 4800MHz
        width: 64 bits
        clock: 100MHz
   *-memory
        description: System Memory
        physical id: 1
        slot: System board or motherboard
        size: 16GiB

As you can see, the lshw command provides a detailed overview of the hardware components in your system. This information can be useful for troubleshooting hardware-related issues, understanding your system's capabilities, and more.

In the next step, you will explore how to use the lshw command to gather more specific hardware information.

Explore System Hardware Information Using lshw

In this step, you will learn how to use the lshw command to explore more detailed hardware information about your system.

The lshw command provides a wide range of options to customize the output and focus on specific hardware components. Let's start by exploring the basic options:

## Display a concise summary of hardware information
sudo lshw -short

## Display detailed information about all hardware components
sudo lshw

## Display information about a specific hardware class, such as network, disk, or memory
sudo lshw -class network
sudo lshw -class disk
sudo lshw -class memory

Example output for sudo lshw -short:

H/W path       Device     Class          Description
========================================================
                         system         Virtual Machine
/0                       bus            Google
/0/1                     memory         16GiB
/0/100                   processor      Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
/0/100/2                 memory         16GiB
/0/100/2/0               memory         16GiB
/0/100/14                network        Ethernet interface
/0/100/1d               bus            USB controller
/0/100/1d/1             input          USB device
/0/100/1d/2             storage        USB device

The lshw -short command provides a concise summary of the hardware components, while the lshw command without any options displays the full, detailed information.

You can also use the -class option to focus on a specific hardware component, such as network, disk, or memory. This can be helpful when you need to quickly gather information about a particular hardware subsystem.

In the next step, you will learn how to customize the lshw output and save the information to a file for further analysis.

Customize lshw Output and Save to a File

In this final step, you will learn how to customize the output of the lshw command and save the information to a file for later reference.

The lshw command provides several options to customize the output, including:

  • -short: Display a concise summary of hardware information
  • -sanitize: Remove sensitive information from the output
  • -html: Generate output in HTML format
  • -xml: Generate output in XML format
  • -json: Generate output in JSON format

Let's start by saving the detailed hardware information to a file in XML format:

sudo lshw -xml > hardware_info.xml

This will save the full hardware information in an XML file named hardware_info.xml in the current directory.

You can also save the output in a more concise, human-readable format, such as HTML:

sudo lshw -html > hardware_info.html

This will generate an HTML file with the hardware information, which you can open in a web browser.

If you only need to focus on specific hardware components, you can use the -class option to filter the output:

## Save network information to a file
sudo lshw -class network -xml > network_info.xml

## Save disk information to a file
sudo lshw -class disk -xml > disk_info.xml

These commands will save the network and disk hardware information to separate XML files, respectively.

The customized output files can be useful for various purposes, such as:

  • Troubleshooting hardware-related issues
  • Documenting your system's hardware configuration
  • Sharing hardware information with others
  • Automating hardware inventory and monitoring tasks

In the final verification step, you will check that the hardware information has been saved to the expected files.

Summary

In this lab, you first learned about the lshw (List Hardware) command and its purpose in providing detailed information about the hardware components of your Linux system. The lshw command can gather information on various hardware components, such as CPU, memory, motherboard, disk drives, network interfaces, and more. You then explored how to use the lshw command to customize the output and focus on specific hardware information. This included learning about the various options available to filter and format the output, as well as how to save the hardware information to a file for future reference.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like