Linux lshw Command Tutorial for Beginners (6 Examples)

The beauty of the Linux command line lies in the fact that you can do almost anything using the command line tools. Even if it involves fetching information on the system's hardware components. If that's what you intend to do, and are looking for a command line way to this, you'll be happy to know you can use the lshw command for it.

In this tutorial, we will discuss this utility using some easy to understand examples. But before we do that, it's worth mentioning that all examples in this article have been tested on an Ubuntu 16.04 LTS machine.

Linux lshw command

As already mentioned, the lshw command lets you fetch hardware info. Here's the syntax of the command:

lshw [options]

And here's how the man page explains the tool:

       lshw  is  a  small tool to extract detailed information on the hardware
       configuration of the machine. It can report exact memory configuration,
       firmware version, mainboard configuration, CPU version and speed, cache
       configuration, bus speed, etc. on DMI-capable x86 or IA-64 systems  and
       on some PowerPC machines (PowerMac G4 is known to work).

       It  currently  supports  DMI  (x86 and IA-64 only), OpenFirmware device
       tree (PowerPC only), PCI/AGP, CPUID (x86), IDE/ATA/ATAPI, PCMCIA  (only
       tested on x86), SCSI and USB.

Following are some Q&A-styled examples that will give you a better idea on how this utility works.

Q1. How to use the lshw command?

For default usage, all you have to do is to run the 'lshw' command without any options.

lshw

Note that you need to execute the lshw command with root privileges.

Following is the output the command produced on my system:

How to use the lshw command

Please note that this is just a small part of the information produced in output.

Q2. How to have device tree output showing hardware paths?

For this, use the -short command line option.

lshw -short

Here's the output the above command produced in my case:

How to have device tree output showing hardware paths

Q3. How make lshw fetch SCSI, USB, IDE and PCI device info?

This info can be fetched using the -businfo option of the lshw command.

lshw -businfo

Here's the output this command produced in my case:

How make lshw fetch SCSI, USB, IDE and PCI device info

Note: You can use -numeric option if you want the tool to also display numeric IDs (for PCI and USB devices).

Q4. How to make lshw display information in HTML format.

There's a dedicated command line option for this: -html. So you can use the tool in the following way:

lshw -html

Here's the output the above command produced on my system:

How to make lshw display information in HTML format

Q5. How to make display information in XML format?

Like HTML output, lshw command can also produce output in the XML format, and the command line option that facilitates this is -xml.

lshw -xml

Here's a sample output in this format:

How to make display information in XML format

Similarly, you can use the -json command line option to display the device tree as a JSON object.

Q6. How to make lshw not emit sensitive info in output?

You'll be glad to know lshw takes care of this requirement as well. Those who don't want the tool to emit potentially sensitive information in output can use the -sanitize option. This way, you can avoid lshw emitting information like IP addresses, serial numbers, and more.

lshw -sanitize

Conclusion

As you'd agree, lshw is the not the command you'd require everyday. But it's definitely a handy tool, for you never know when you might want to access your system's hardware details. We discussed basic usage of the tool here - for more info, head to the command's man page.

Himanshu Arora

About Himanshu Arora

Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu's work has also been featured in some of world's other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.

Share this page:

Suggested articles

0 Comment(s)

Add comment