The lshw (List Hardware) command in Linux is a powerful tool that provides users with detailed information about the hardware configuration of their system. It is a small but robust command-line utility that reports precise details about various hardware components such as memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, and more. This tool is particularly useful for system administrators and power users who need to perform hardware troubleshooting or inventory.
Table of Content
- Understanding lshw Command
- How to Use lshw Command in Linux
- Practical Examples of lshw Command
- Conclusion
Understanding lshw Command
The lshw command is a versatile tool that provides detailed information about the hardware components of a Linux system. It can be used to gather information about various components, including:
- CPU (Central Processing Unit)
- Memory (RAM)
- Storage (Hard drives, SSDs, USB devices)
- Graphics (Video cards)
- Network (Network interfaces)
- Input devices (Keyboard, mouse)
- Other devices (USB devices, sound cards, etc.)
How to Use lshw Command in Linux
The lshw command needs to be run with root permissions to display full information; otherwise, it will only show partial information. The basic syntax of the lshw command is as follows:
lshw [-format] [options]
The command supports several formats for output, such as HTML, XML, JSON, and plain text, which can be specified using the -html, -xml, -json, and -short options, respectively. Additionally, the -businfo option provides a list of devices showing bus information, including SCSI, USB, IDE, and PCI addresses.
lshw offers many other options for customizing the output:
Options |
Descriptions |
capabilities |
Display device capabilities. |
disabled |
Show disabled devices. |
logical |
Show logical devices (e.g., RAID arrays). |
options |
Display configuration options for devices. |
short |
Display a short summary of each device. |
verbose |
Display more detailed information. |
Practical Examples of lshw Command
Here are some practical examples of how to use the lshw command:
Example 1: Display Full Hardware Information
To view the complete hardware information, simply run the below command. This will output a detailed report of all detected hardware components, including their names, descriptions, and specifications:
sudo lshw
Example 2: Output in HTML Format
For a more readable format, especially when documenting, you can output the information in HTML:
sudo lshw -html
Example 3: Hardware Information in XML Format
To get the hardware information in XML format, which can be useful for parsing in scripts, use:
sudo lshw -xml
Example 4: Compact Listing of Hardware Paths
For a brief overview of hardware paths, the -short option is handy:
sudo lshw -short
Example 5: Display Bus Information
To list devices along with their bus information:
sudo lshw -businfo
Example 6: Filter by Class of Hardware
If you’re interested in a specific class of hardware, such as network devices, you can filter the output accordingly. To focus on specific hardware classes, you can use the -class option:
sudo lshw -class network
Example 7: Display Specific Hardware Details
To get detailed information about a particular hardware class, like memory, use –class memory as below:
sudo lshw -C memory
Example 8: Filtering by Device
You can filter the output by device name or a portion of the name:
List information about a specific network interface
lshw -C network -filter "enp0s3"
List information about all devices containing “USB” in their name
lshw -filter "USB"
Example 9: Detailed Output
To get more detailed information about a specific component, you can use the -json or -xml options to output the data in JSON or XML format:
Let’s show output CPU information in JSON format:
sudo lshw -class cpu -json
Output storage device information in XML format:
sudo lshw -class storage -xml
By understanding the lshw command and its various options, you can effectively gather information about your Linux system’s hardware and use it for troubleshooting, configuration, and other purposes.
Conclusion
The lshw command is a versatile and comprehensive tool for hardware analysis on Linux systems. Its ability to output detailed hardware information in various formats makes it an indispensable utility for system diagnostics and reporting. For more advanced usage and additional examples, users can refer to the lshw man page for further reading and practical examples.
Remember, while lshw is a non-destructive read-only tool, it’s always good practice to be cautious when running commands with root privileges. Always ensure that you understand the command and its options before executing it on your system.
Keep visting LinuxWorld for more valuable guides.