Linux shell编程学习笔记57:lshw命令 获取cpu设备信息

0 前言

Linux中,获取cpu信息的命令很多,除了我们已经研究的 cat /proc/cpuinfo、lscpu、nproc、hwinfo --cpu 命令,还有 lshw命令。

1 lshw命令的功能

lshw命令源自英文list hardware,即列出系统的硬件信息,这些硬件包括cpu、内存、硬盘、pci设备等等。今天我们主要是使用 lshw命令查询cpu信息。

[purpleendurer @ bash ~ ]lshw --help
Hardware Lister (lshw) - B.02.17
usage: lshw [-format] [-options ...]
       lshw -version

	-version        print program version (B.02.17)

format can be
	-html           output hardware tree as HTML
	-xml            output hardware tree as XML
	-short          output hardware paths
	-businfo        output bus information

options can be
	-class CLASS    only show a certain class of hardware
	-C CLASS        same as '-class CLASS'
	-c CLASS        same as '-class CLASS'
	-disable TEST   disable a test (like pci, isapnp, cpuid, etc. )
	-enable TEST    enable a test (like pci, isapnp, cpuid, etc. )
	-quiet          don't display status
	-sanitize       sanitize output (remove sensitive information like serial numbers, etc.)
	-numeric        output numeric IDs (for PCI, USB, etc.)

[purpleendurer @ bash ~ ]

2 使用lshw命令查询cpu信息

2.1 lshw -C cpu:查询cpu信息

[purpleendurer @ bash ~ ]lshw -C cpu
WARNING: you should run this program as super-user.
  *-cpu:0                 
       physical id: 7
       bus info: cpu@0
       size: 2600MHz
       capacity: 2600MHz
       capabilities: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpufreq
  *-cpu:1
       physical id: 8
       bus info: cpu@1
       size: 2600MHz
       capacity: 2600MHz
       capabilities: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpufreq
  *-cpu:2
       physical id: 9
       bus info: cpu@2
       size: 2600MHz
       capacity: 2600MHz
       capabilities: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpufreq
  *-cpu:3
       physical id: a
       bus info: cpu@3
       size: 2600MHz
       capacity: 2600MHz
       capabilities: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpufreq
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
[purpleendurer @ bash ~ ]

这是关于某个 CPU 的信息。具体含义如下:

序号 信息 含义
1 -cpu:0 CPU编号:表示这是第一个 CPU
2 physical id: 7 物理 ID是 7
3 bus info: cpu@0 总线信息
4 size: 2600MHz 尺寸是 2600MHz,即主频为 2.6GHz
5 capacity: 2600MHz 容量也是 2600MHz,即主频为 2.6GHz
6 capabilities: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpufreq 功能:包括 fp(浮点运算)、asimd(SIMD指令集)、evtstrm(事件跟踪)、aes(AES加密指令集)、pmull(多项式乘法)、sha1(SHA-1散列函数加速)、sha2(SHA-2散列函数加速)、crc32(CRC32校验)、cpufreq(CPU频率调节)

2.2 lshw -C cpu -short:查询和显示简短cpu信息

[purpleendurer @ bash ~ ]lshw -C cpu -short
WARNING: you should run this program as super-user.
H/W path    Device      Class      Description
==============================================
/0/7                    processor  
/0/8                    processor  
/0/9                    processor  
/0/a                    processor  
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
[purpleendurer @ bash ~ ]

2.3 lshw -C cpu -short:查询并以xml格式显示cpu信息

XML 复制代码
[purpleendurer @ bash ~ ]lshw -C cpu -xml
WARNING: you should run this program as super-user.
<?xml version="1.0" standalone="yes" ?>
<!-- generated by lshw-B.02.17 -->
<!-- GCC 5.4.0 20160609 -->
<!-- Linux 4.4.131-20200710.kylin.desktop-generic #kylin SMP Fri Jul 10 13:46:24 CST 2020 aarch64 -->
<!-- GNU libc 2 (glibc 2.23) -->
<!-- WARNING: not running as root -->
<list>
  <node id="cpu:0" claimed="true" class="processor" handle="">
   <physid>7</physid>
   <businfo>cpu@0</businfo>
   <size units="Hz">2600000000</size>
   <capacity units="Hz">2600000000</capacity>
   <capabilities>
    <capability id="fp" >Floating point instructions</capability>
    <capability id="asimd" >Advanced SIMD</capability>
    <capability id="evtstrm" >Event stream</capability>
    <capability id="aes" >AES instructions</capability>
    <capability id="pmull" >PMULL instruction</capability>
    <capability id="sha1" >SHA1 instructions</capability>
    <capability id="sha2" >SHA2 instructions</capability>
    <capability id="crc32" >CRC extension</capability>
    <capability id="cpufreq" >CPU Frequency scaling</capability>
   </capabilities>
  </node>
  <node id="cpu:1" claimed="true" class="processor" handle="">
   <physid>8</physid>
   <businfo>cpu@1</businfo>
   <size units="Hz">2600000000</size>
   <capacity units="Hz">2600000000</capacity>
   <capabilities>
    <capability id="fp" >Floating point instructions</capability>
    <capability id="asimd" >Advanced SIMD</capability>
    <capability id="evtstrm" >Event stream</capability>
    <capability id="aes" >AES instructions</capability>
    <capability id="pmull" >PMULL instruction</capability>
    <capability id="sha1" >SHA1 instructions</capability>
    <capability id="sha2" >SHA2 instructions</capability>
    <capability id="crc32" >CRC extension</capability>
    <capability id="cpufreq" >CPU Frequency scaling</capability>
   </capabilities>
  </node>
  <node id="cpu:2" claimed="true" class="processor" handle="">
   <physid>9</physid>
   <businfo>cpu@2</businfo>
   <size units="Hz">2600000000</size>
   <capacity units="Hz">2600000000</capacity>
   <capabilities>
    <capability id="fp" >Floating point instructions</capability>
    <capability id="asimd" >Advanced SIMD</capability>
    <capability id="evtstrm" >Event stream</capability>
    <capability id="aes" >AES instructions</capability>
    <capability id="pmull" >PMULL instruction</capability>
    <capability id="sha1" >SHA1 instructions</capability>
    <capability id="sha2" >SHA2 instructions</capability>
    <capability id="crc32" >CRC extension</capability>
    <capability id="cpufreq" >CPU Frequency scaling</capability>
   </capabilities>
  </node>
  <node id="cpu:3" claimed="true" class="processor" handle="">
   <physid>a</physid>
   <businfo>cpu@3</businfo>
   <size units="Hz">2600000000</size>
   <capacity units="Hz">2600000000</capacity>
   <capabilities>
    <capability id="fp" >Floating point instructions</capability>
    <capability id="asimd" >Advanced SIMD</capability>
    <capability id="evtstrm" >Event stream</capability>
    <capability id="aes" >AES instructions</capability>
    <capability id="pmull" >PMULL instruction</capability>
    <capability id="sha1" >SHA1 instructions</capability>
    <capability id="sha2" >SHA2 instructions</capability>
    <capability id="crc32" >CRC extension</capability>
    <capability id="cpufreq" >CPU Frequency scaling</capability>
   </capabilities>
  </node>
</list>
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
[purpleendurer @ bash ~ ]

2.4 lshw -C cpu -html:查询并以htm格式显示cpu信息

XML 复制代码
[purpleendurer @ bash ~ ]lshw -C cpu -html
WARNING: you should run this program as super-user.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator"  content="lshw-B.02.17" />
<style type="text/css">
  .first {font-weight: bold; margin-left: none; padding-right: 1em;vertical-align: top; }
  .second {padding-left: 1em; width: 100%; vertical-align: center; }
  .id {font-family: monospace;}
  .indented {margin-left: 2em; border-left: dotted thin #dde; padding-bottom: 1em; }
  .node {border: solid thin #ffcc66; padding: 1em; background: #ffffcc; }
  .node-unclaimed {border: dotted thin #c3c3c3; padding: 1em; background: #fafafa; color: red; }
  .node-disabled {border: solid thin #f55; padding: 1em; background: #fee; color: gray; }
</style>
<title>gxxc-ce3000f</title>
</head>
<body>
<div class="indented">
<div class="indented">
</div>
<div class="indented">
        <div class="indented">
    <table width="100%" class="node" summary="attributes of cpu:0">
 <thead><tr><td class="first">id:</td><td class="second"><div class="id">cpu:0</div></td></tr></thead>
 <tbody>
       <tr><td class="first">physical id: </td><td class="second"><div class="id">7</div></td></tr>
       <tr><td class="first">bus info: </td><td class="second"><div class="id">cpu@0</div></td></tr>
       <tr><td class="first">size: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capacity: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capabilities: </td><td class="second"><dfn title="Floating point instructions">fp</dfn> <dfn title="Advanced SIMD">asimd</dfn> <dfn title="Event stream">evtstrm</dfn> <dfn title="AES instructions">aes</dfn> <dfn title="PMULL instruction">pmull</dfn> <dfn title="SHA1 instructions">sha1</dfn> <dfn title="SHA2 instructions">sha2</dfn> <dfn title="CRC extension">crc32</dfn> <dfn title="CPU Frequency scaling">cpufreq</dfn> </td></tr>
 </tbody>    </table></div>
    </div>
<div class="indented">
        <div class="indented">
    <table width="100%" class="node" summary="attributes of cpu:1">
 <thead><tr><td class="first">id:</td><td class="second"><div class="id">cpu:1</div></td></tr></thead>
 <tbody>
       <tr><td class="first">physical id: </td><td class="second"><div class="id">8</div></td></tr>
       <tr><td class="first">bus info: </td><td class="second"><div class="id">cpu@1</div></td></tr>
       <tr><td class="first">size: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capacity: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capabilities: </td><td class="second"><dfn title="Floating point instructions">fp</dfn> <dfn title="Advanced SIMD">asimd</dfn> <dfn title="Event stream">evtstrm</dfn> <dfn title="AES instructions">aes</dfn> <dfn title="PMULL instruction">pmull</dfn> <dfn title="SHA1 instructions">sha1</dfn> <dfn title="SHA2 instructions">sha2</dfn> <dfn title="CRC extension">crc32</dfn> <dfn title="CPU Frequency scaling">cpufreq</dfn> </td></tr>
 </tbody>    </table></div>
    </div>
<div class="indented">
        <div class="indented">
    <table width="100%" class="node" summary="attributes of cpu:2">
 <thead><tr><td class="first">id:</td><td class="second"><div class="id">cpu:2</div></td></tr></thead>
 <tbody>
       <tr><td class="first">physical id: </td><td class="second"><div class="id">9</div></td></tr>
       <tr><td class="first">bus info: </td><td class="second"><div class="id">cpu@2</div></td></tr>
       <tr><td class="first">size: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capacity: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capabilities: </td><td class="second"><dfn title="Floating point instructions">fp</dfn> <dfn title="Advanced SIMD">asimd</dfn> <dfn title="Event stream">evtstrm</dfn> <dfn title="AES instructions">aes</dfn> <dfn title="PMULL instruction">pmull</dfn> <dfn title="SHA1 instructions">sha1</dfn> <dfn title="SHA2 instructions">sha2</dfn> <dfn title="CRC extension">crc32</dfn> <dfn title="CPU Frequency scaling">cpufreq</dfn> </td></tr>
 </tbody>    </table></div>
    </div>
<div class="indented">
        <div class="indented">
    <table width="100%" class="node" summary="attributes of cpu:3">
 <thead><tr><td class="first">id:</td><td class="second"><div class="id">cpu:3</div></td></tr></thead>
 <tbody>
       <tr><td class="first">physical id: </td><td class="second"><div class="id">a</div></td></tr>
       <tr><td class="first">bus info: </td><td class="second"><div class="id">cpu@3</div></td></tr>
       <tr><td class="first">size: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capacity: </td><td class="second">2600MHz</td></tr>
       <tr><td class="first">capabilities: </td><td class="second"><dfn title="Floating point instructions">fp</dfn> <dfn title="Advanced SIMD">asimd</dfn> <dfn title="Event stream">evtstrm</dfn> <dfn title="AES instructions">aes</dfn> <dfn title="PMULL instruction">pmull</dfn> <dfn title="SHA1 instructions">sha1</dfn> <dfn title="SHA2 instructions">sha2</dfn> <dfn title="CRC extension">crc32</dfn> <dfn title="CPU Frequency scaling">cpufreq</dfn> </td></tr>
 </tbody>    </table></div>
    </div>
<div class="indented">
</div>
<div class="indented">
<div class="indented">
</div>
</div>
<div class="indented">
<div class="indented">
</div>
</div>
<div class="indented">
</div>
<div class="indented">
</div>
<div class="indented">
<div class="indented">
</div>
</div>
<div class="indented">
<div class="indented">
</div>
</div>
</div>
<div class="indented">
</div>
</body>
</html>
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
[purpleendurer @ bash ~ ]
相关推荐
云飞云共享云桌面7 分钟前
8位机械工程师如何共享一台图形工作站算力?
linux·服务器·网络
Peter_chq44 分钟前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端
一坨阿亮2 小时前
Linux 使用中的问题
linux·运维
dsywws3 小时前
Linux学习笔记之vim入门
linux·笔记·学习
幺零九零零3 小时前
【C++】socket套接字编程
linux·服务器·网络·c++
小林熬夜学编程5 小时前
【Linux系统编程】第四十一弹---线程深度解析:从地址空间到多线程实践
linux·c语言·开发语言·c++·算法
程思扬5 小时前
为什么Uptime+Kuma本地部署与远程使用是网站监控新选择?
linux·服务器·网络·经验分享·后端·网络协议·1024程序员节
sun0077005 小时前
拷贝 cp -rdp 和 cp -a
linux·运维·服务器
wowocpp6 小时前
ubuntu 22.04 server 安装 anaconda3
linux·运维·ubuntu
乡村农夫6 小时前
cuda 环境搭建
linux