Linux lshw Command Tutorial for Beginners (6 Examples)
On this page
- Linux lshw command
- Q1. How to use the lshw command?
- Q2. How to have device tree output showing hardware paths?
- Q3. How make lshw fetch SCSI, USB, IDE and PCI device info?
- Q4. How to make lshw display information in HTML format.
- Q5. How to make display information in XML format?
- Q6. How to make lshw not emit sensitive info in output?
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:
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.
Note that you need to execute the lshw command with root privileges.
Following is the output the command produced on my system:
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.
Here's the output the above command produced in my case:
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.
Here's the output this command produced in my case:
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:
Here's the output the above command produced on my system:
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.
Here's a sample output in this 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.
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.