0


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:0CPU编号:表示这是第一个 CPU2physical id: 7物理 ID是 73bus info: cpu@0总线信息4size: 2600MHz尺寸是 2600MHz,即主频为 2.6GHz5capacity: 2600MHz容量也是 2600MHz,即主频为 2.6GHz6capabilities: 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信息

[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信息

[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 ~ ]


本文转载自: https://blog.csdn.net/Purpleendurer/article/details/139455904
版权归原作者 紫郢剑侠 所有, 如有侵权,请联系我们删除。

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

还没有评论