How to use the command 'lshw' (with examples)

How to use the command 'lshw' (with examples)

The lshw (short for “list hardware”) command is a powerful utility in Linux used to gather comprehensive details about the system’s hardware components. It provides detailed information on various aspects of your computer’s hardware, such as CPU, memory, storage, and network interfaces, making it a valuable tool for system administrators and technical users who need to monitor and troubleshoot system hardware configurations.

Launch the GUI

Code:

sudo lshw -X

Motivation:

Sometimes, viewing hardware details in a graphical interface can make it easier for users to understand their system’s configuration without having to parse through extensive command-line output. The graphical user interface (GUI) offers an intuitive way to navigate complex data structures, highlighting key components and providing visual cues that simplify hardware analysis and troubleshooting.

Explanation:

  • sudo: This command requires administrative privileges to access detailed hardware information, hence the use of sudo to execute it with root permissions.
  • lshw: Invokes the hardware listing utility.
  • -X: Launches the lshw tool with a graphical user interface, presenting hardware details in a more accessible format.

Example Output:

Upon execution, a window appears with a hierarchical representation of hardware information, partitioned into categories like memory, CPU, storage, network, etc., allowing users to expand and collapse each category for more or less detail as needed.

List all hardware in tabular format

Code:

sudo lshw -short

Motivation:

Listing hardware information in a condensed and organized table format is particularly beneficial for quick overviews and comparisons. This format provides a straightforward summary of the system’s hardware, making it easier to glance at essential specifications like hardware parts and their configurations. System administrators can use this format to swiftly assess the system’s hardware status without digging through lengthy descriptions.

Explanation:

  • sudo: Again, administrative privileges are required, as accessing complete hardware details necessitates root access.
  • lshw: The command used for listing hardware details.
  • -short: Outputs the hardware information in a summarized tabular format, where each hardware component is represented in a single row.

Example Output:

A simple table with columns such as ‘H/W path,’ ‘Device,’ ‘Class,’ and ‘Description’ is displayed, each providing compact information on the various hardware components installed on the system, such as the processor, memory modules, disk drives, etc.

List all disks and storage controllers in tabular format

Code:

sudo lshw -class disk -class storage -short

Motivation:

There are instances when you need to focus solely on storage-related components, such as when diagnosing disk issues or assessing storage capacity. Narrowing the output to show only disks and storage controllers allows for targeted analysis of these specific components, aiding in troubleshooting and inventory management of storage resources.

Explanation:

  • sudo: Administrative rights are needed to access detailed hardware information.
  • lshw: The command for retrieving hardware details.
  • -class disk: Filters the output to include only hardware components classified under ‘disk’, such as hard drives and SSDs.
  • -class storage: Includes storage controllers in the results, which manage the data flow between the disks and the computer.
  • -short: Presents the filtered information in a condensed table format.

Example Output:

A concise table displays relevant information about disk drives and storage controllers, showing columns for ‘H/W path,’ ‘Device,’ ‘Class,’ and ‘Description’, providing an overview of the system’s storage setup.

Save all network interfaces to an HTML file

Code:

sudo lshw -class network -html > interfaces.html

Motivation:

Saving hardware information as an HTML file provides a shareable, browser-friendly format that can be easily archived or shared with others for collaborative diagnostics or documentation purposes. In cases where network configuration needs to be reviewed or shared with technicians, having it in an HTML format can facilitate easier access and dissemination.

Explanation:

  • sudo: Grants necessary root permissions to the command for accessing comprehensive hardware data.
  • lshw: The utility to list hardware configurations.
  • -class network: Limits the output to include only network interfaces.
  • -html: Outputs the data in HTML format, which is ideal for web viewing and sharing.
  • > interfaces.html: Redirects the HTML output to a file named ‘interfaces.html’, storing the network configuration details externally.

Example Output:

Running this command creates an ‘interfaces.html’ file, which when opened in a web browser shows a neatly formatted page listing all network interfaces. This file includes details such as interface names, types, and configurations, neatly organized in regular HTML tables.

Conclusion:

The lshw command is an invaluable tool for those looking to gather detailed information about their system’s hardware components. Whether you are viewing data graphically, checking a summary in a table, or saving specific details like network interfaces to an HTML file, lshw offers flexible options to suit various informational needs. It simplifies hardware management and monitoring for both novice users and seasoned system administrators.

Tags :

Related Posts

How to use the command 'systemd-nspawn' (with examples)

How to use the command 'systemd-nspawn' (with examples)

The systemd-nspawn command is a versatile and powerful tool used to spawn and manage lightweight containers, offering an easy way to run processes in isolated environments.

Read More
How to use the command 'lwp-request' (with examples)

How to use the command 'lwp-request' (with examples)

The lwp-request command is a simple and powerful command-line HTTP client built with the libwww-perl library.

Read More
How to use the command 'plutil' (with examples)

How to use the command 'plutil' (with examples)

The plutil command is a powerful utility in macOS that allows users to interact with property list files, commonly referred to as plist files.

Read More