20+ lshw command examples in Linux [Cheat Sheet]

Introduction to lshw command

lshw is a command-line 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.

It should be available by default in most distributions but you can install it by installing lshw package using the default package manager such as yum, dnf, apt etc.

Advertisement

 

Syntax to use lshw command

lshw needs root permission to display full information otherwise, it displays only partial information.

The syntax is:

# lshw [-format] [options]

The formats available are:

  • -html: Outputs the device tree as an HTML page.
  • -xml: Outputs the device tree as an XML tree.
  • -json: Output the device tree as a JSON object
  • -short: Outputs the device tree showing hardware paths
  • -businfo: Outputs the device list showing bus information

 

Different examples to use lshw command

1. lshw command to display full hardware information

You can view the full information of hardware using lshw command with super-user only.

# lshw

Sample Output:

lshw command to display full hardware information

 

2. lshw command to display information in HTML format

You can change the output format to HTML using -html option. It prints the hardware information in HTML format.

Advertisement
# lshw -html

Sample Output:

lshw command to display information in html format

 

3. Display hardware information in XML format with lshw command

You can use -xml option to print the hardware information in XML format.

# lshw -xml

Sample Output:

lshw command to display information in xml format

 

4. lshw command to display information in JSON format

You can view the hardware information in JSON format using -json option.

# lshw -json

Sample Output:

lshw command to display information in json format

 

5. Display hardware paths using lshw command

You can use -short option to display hardware paths in a compact format.

# lshw -short

Sample Output:

lshw command to display hardware paths

 

6. lshw command to display bus information

-businfo option displays the device list showing bus information, detailing SCSI, USB, IDE, and PCI addresses.

Advertisement
# lshw -businfo

Sample Output:

lshw command to display bus information

 

7. lshw command to display the specific class of hardware

You can use -c, -C, or -class option to view the information on a given class of hardware. class can be found using lshw -short or lshw -businfo.

# lshw -c class 

OR

# lshw -C class 

OR

# lshw -class class 

Sample Output:

To list the memory information, you can use:

lshw command to display information of given class

 

8. Show system information with lshw command

To print the system information, we can use -class system as shown below:

20+ lshw command examples in Linux [Cheat Sheet]

 

9. Show display information with lshw command

We can use -class display to print the display information of the Linux server:

20+ lshw command examples in Linux [Cheat Sheet]

 

10. Show network information with lshw command

We can display the hardware details of the NIC card interfaces installed on the Linux server using -class network argument:

root@ubuntu:~# lshw -class network
  *-network:0
       description: Ethernet interface
       product: 82540EM Gigabit Ethernet Controller
       vendor: Intel Corporation
       physical id: 3
       bus info: pci@0000:00:03.0
       logical name: enp0s3
       version: 02
       serial: 08:00:27:84:07:7f
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 32 bits
       clock: 66MHz
       capabilities: pm pcix bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=e1000 driverversion=7.3.21-k8-NAPI duplex=full ip=10.0.2.15 latency=64 link=yes mingnt=255 multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:19 memory:f0200000-f021ffff ioport:d020(size=8)
  *-network:1
       description: Ethernet interface
       product: 82540EM Gigabit Ethernet Controller
       vendor: Intel Corporation
       physical id: 8
       bus info: pci@0000:00:08.0
       logical name: enp0s8
       version: 02
       serial: 08:00:27:aa:34:d4
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 32 bits
       clock: 66MHz
       capabilities: pm pcix bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=e1000 driverversion=7.3.21-k8-NAPI duplex=full ip=192.168.0.189 latency=64 link=yes mingnt=255 multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:16 memory:f0820000-f083ffff ioport:d240(size=8)

 

11. Show storage information with lshw command

You can use -class storage to print the available storage information:

root@ubuntu:~# lshw -class storage
  *-ide
       description: IDE interface
       product: 82371AB/EB/MB PIIX4 IDE
       vendor: Intel Corporation
       physical id: 1.1
       bus info: pci@0000:00:01.1
       version: 01
       width: 32 bits
       clock: 33MHz
       capabilities: ide isa_compatibility_mode_controller__supports_both_channels_switched_to_pci_native_mode__supports_bus_mastering bus_master
       configuration: driver=ata_piix latency=64
       resources: irq:0 ioport:1f0(size=8) ioport:3f6 ioport:170(size=8) ioport:376 ioport:d000(size=16)
  *-storage
       description: SATA controller
       product: 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode]
       vendor: Intel Corporation
       physical id: d
       bus info: pci@0000:00:0d.0
       version: 02
       width: 32 bits
       clock: 33MHz
       capabilities: storage pm ahci_1.0 bus_master cap_list
       configuration: driver=ahci latency=64
       resources: irq:21 ioport:d248(size=8) ioport:d250(size=4) ioport:d258(size=8) ioport:d260(size=4) ioport:d270(size=16) memory:f0840000-f0841fff
  *-scsi:0
       physical id: 3
       logical name: scsi1
       capabilities: emulated
  *-scsi:1
       physical id: 4
       logical name: scsi2
       capabilities: emulated

 

12. Show connected disk information with lshw command

To list the details of the connected disk we can use -class disk argument as shown below:

20+ lshw command examples in Linux [Cheat Sheet]

 

13: Get processor information with lshw command

You can get the processor details of your Linux server using -class processor argument as shown below:

root@ubuntu:~# lshw -class processor
  *-cpu
       product: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
       vendor: Intel Corp.
       physical id: 2
       bus info: cpu@0
       width: 64 bits
       capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp x86-64 constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase avx2 invpcid rdseed clflushopt md_clear flush_l1d

 

14. Get motherboard information with lshw command

You can get the details about your Linux server's motherboard using -class bus argument:

20+ lshw command examples in Linux [Cheat Sheet]

 

15. Save lshw command output into a different file

By default lshw will print a very long summary of details from your Linux server hardware. We can save the output to a different file to analyse it later by using the following method:

~]# lshw > /tmp/lshw_output.txt

~]# ls -l /tmp/lshw_output.txt
-rw-r--r-- 1 root root 12435 Nov 26 00:10 /tmp/lshw_output.txt

So, here we have saved the output of lshw command into lshw_output.txt file.

 

16. lshw command to enable system hardware components

You can enable different parameters of the system using -enable option followed by hardware component which can be:

  • dmi (for DMI/SMBIOS extensions)
  • device-tree (for OpenFirmware device tree)
  • spd (for memory Serial Presence Detect)
  • memory (for memory-size guessing heuristics)
  • cpuinfo (for kernel-reported CPU detection)
  • cpuid (for CPU detection)
  • pci (for PCI/AGP access)
  • isapnp (for ISA PnP extensions)
  • pcmcia (for PCMCIA/PCCARD)
  • ide (for IDE/ATAPI)
  • usb (for USB devices)
  • scsi (for SCSI)
  • network (for network interfaces detection).
# lshw -enable test

Sample Output:

For example, to enable CPU detection, you can use the following command.

lshw command to enable a test

 

17. lshw command to disable any hardware component

You can disable a system parameter using -disable option followed by the test.

# lshw -disable test 

Sample Output:

To disable CPU detection, you can use:

lshw command to disable a test

 

18. lshw command to hide display status

-quiet option is used to not display status in the output.

# lshw -quiet

Sample Output:

lshw command to not display status

 

19. Hide sensitive information from output with lshw command

You can use -sanitize option to remove potentially sensitive information from the output (IP addresses, serial numbers, etc.).

# lshw -sanitize

Sample Output:

lshw command to remove sensitive information

 

20. Display numeric IDs using lshw command

-numeric option displays numeric IDs (for PCI and USB devices).

# lshw -numeric

Sample Output:

lshw command to display numeric IDs

 

21. lshw command to exclude timestamps from output

-notime option is used to exclude volatile attributes (timestamps) from the output.

# lshw -notime

 

Conclusion

lshw is a hardware lister tool that is very helpful to extract detailed information on the hardware of the system. We hope you will be now able to run lshw command to get hardware information. If you still have any confusion, feel free to ask us in the comment section.

 

What's Next

10 different methods to check disk space in Linux

 

Further Reading

man page for lshw command

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment