lshw Command in Linux: Get Hardware Details

In Linux systems, knowing the details of hardware is very important for system administrators and users. The lshw (list hardware) command is a powerful tool that helps us get detailed information about various hardware components in the system. Whether it is CPU, memory, disk, network adapter or other hardware devices, the lshw command can provide detailed information.

1. Install lshw

In most Linux distributions, lshw is installed by default. If your system does not have this command installed, you can install it through the package manager.

  • Debian/Ubuntu system:
sudo apt-get install lshw

  • CentOS/RHEL system:
sudo yum install lshw
  • Fedora system:
sudo dnf install lshw

2. Basic Usage

The lshw command is a powerful and complex tool that supports a wide variety of parameters and options. In the simplest usage, we can run lshwcommands directly in the terminal to get all hardware information.

sudo lshw

After running the above command, lshw will display the hardware information of the system, including CPU, memory, disk, network adapter, display adapter, etc. The output may be very detailed, so in actual use, we may need to combine some parameters to filter the required information.

The server on my side is a Huawei cloud server.

3. Get CPU information

In this section, we will focus on how to use the lshw command to get CPU (Central Processing Unit) details.

sudo lshw -C cpu

After running the above command, lshw will only display information related to CPU. The output may include detailed information such as CPU model, number of cores, number of threads, clock frequency, etc.

Example:

serial number describe product Physical ID bus information width speed
1 CPU Intel® Core™ i7-8700 CPU 0 00 64 bit 3600MHz

4. View memory information

Next, we will introduce how to use the lshw command to view the memory information of the system.

sudo lshw -C memory

After running the above command, lshw will only display information related to memory. The output may include details such as memory capacity, model, speed, manufacturer, etc.

Example:

serial number describe product Physical ID bus information width speed capacity
1 Memory 8GiB DIMM DDR4 0 00 64 bit 2400MHz 8GiB

5. Hard disk and partition information

The lshw command can also be used to get detailed information about hard drives and partitions. Next, we show how to view this information.

sudo lshw -C disk

After running the above command, lshw will only display information related to the hard disk. The output result may include detailed information such as hard disk model, capacity, and partition information.

Example:

serial number describe product Physical ID bus information width speed capacity
1 disk KINGSTON SA400S37240 0 00 32 bit 6Gbps 223GiB
2 disk WDC WD5000AAKX-60U6A 1 00 32 bit 6Gbps 465GiB
3 disk Seagate Expansion 2 01 32 bit 5Gbps 1.8 TiB

6. Display network adapter information

The lshw command can also help us view the network adapter information in the system.

sudo lshw -C network

After running the above command, lshw will only display information related to the network adapter. The output may include details such as network adapter model, MAC address, IP address, speed, etc.

Example:

serial number describe product logical name Physical ID bus information width speed capacity
1 ethernet Realtek enp2s0 0 pci@0000:02:00.0 64 bit 1000Mbit/s
2 radio waves Intel wlp3s0 1 pci@0000:03:00.0 64 bit 867Mbit/s

7. View display adapter information

If you need to get detailed information about the display adapters in your system, you can use another subcommand of the lshw command.

sudo lshw -C display

After running the above command, lshw will only display information related to the display adapter. The output may include details such as display adapter model, resolution, vendor, etc.

Example:

serial number describe product Physical ID bus information width speed capacity
1 display controller NVIDIA GM204 0 pci@0000:01:00.0 64 bit 8GT/s
2 display controller Intel Haswell-ULT 1 pci@0000:00:02.0 64 bit 5 GT/s

8. Obtain other hardware information

In addition to the hardware information described above, the lshw command can also be used to obtain detailed information about other hardware components. For example, sound cards, USB controllers, SCSI controllers, etc.

sudo lshw -C multimedia  # 声卡信息
sudo lshw -C usb         # USB控制器信息
sudo lshw -C scsi        # SCSI控制器信息

Each subcommand will only display information related to the corresponding hardware component.

in conclusion

The lshw command is a powerful and flexible tool that helps us easily obtain detailed information about various hardware components in a Linux system. Whether it is CPU, memory, hard disk, network adapter or other hardware devices, lshw can provide detailed information. The usages described in this article can give you a better understanding of your system and provide valuable reference when troubleshooting, performance optimization, or hardware upgrades are required.

Because the information output by the lshw command can be very large, when viewing hardware information, we recommend using it in conjunction with filtering tools such as grep to view only the content you are interested in.

Guess you like

Origin blog.csdn.net/weixin_43025343/article/details/131813767