Merge pull request #15744 from way-ww/master

翻译完成
This commit is contained in:
Xingyu.Wang 2019-10-04 10:01:31 +08:00 committed by GitHub
commit 672fe0aae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 399 additions and 417 deletions

View File

@ -1,417 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (way-ww)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux commands to display your hardware information)
[#]: via: (https://opensource.com/article/19/9/linux-commands-hardware-information)
[#]: author: (Howard Fosdick https://opensource.com/users/howtechhttps://opensource.com/users/sethhttps://opensource.com/users/sethhttps://opensource.com/users/seth)
Linux commands to display your hardware information
======
Get the details on what's inside your computer from the command line.
![computer screen ][1]
There are many reasons you might need to find out details about your computer hardware. For example, if you need help fixing something and post a plea in an online forum, people will immediately ask you for specifics about your computer. Or, if you want to upgrade your computer, you'll need to know what you have and what you can have. You need to interrogate your computer to discover its specifications.
The easiest way is to do that is with one of the standard Linux GUI programs:
* [i-nex][2] collects hardware information and displays it in a manner similar to the popular [CPU-Z][3] under Windows.
* [HardInfo][4] displays hardware specifics and even includes a set of eight popular benchmark programs you can run to gauge your system's performance.
* [KInfoCenter][5] and [Lshw][6] also display hardware details and are available in many software repositories.
Alternatively, you could open up the box and read the labels on the disks, memory, and other devices. Or you could enter the boot-time panels—the so-called UEFI or BIOS panels. Just hit [the proper program function key][7] during the boot process to access them. These two methods give you hardware details but omit software information.
Or, you could issue a Linux line command. Wait a minute… that sounds difficult. Why would you do this?
Sometimes it's easy to find a specific bit of information through a well-targeted line command. Perhaps you don't have a GUI program available or don't want to install one.
Probably the main reason to use line commands is for writing scripts. Whether you employ the Linux shell or another programming language, scripting typically requires coding line commands.
Many line commands for detecting hardware must be issued under root authority. So either switch to the root user ID, or issue the command under your regular user ID preceded by **sudo**:
```
`sudo <the_line_command>`
```
and respond to the prompt for the root password.
This article introduces many of the most useful line commands for system discovery. The quick reference chart at the end summarizes them.
### Hardware overview
There are several line commands that will give you a comprehensive overview of your computer's hardware.
The **inxi** command lists details about your system, CPU, graphics, audio, networking, drives, partitions, sensors, and more. Forum participants often ask for its output when they're trying to help others solve problems. It's a standard diagnostic for problem-solving:
```
`inxi -Fxz`
```
The **-F** flag means you'll get full output, **x** adds details, and **z** masks out personally identifying information like MAC and IP addresses.
The **hwinfo** and **lshw** commands display much of the same information in different formats:
```
`hwinfo --short`
```
or
```
`lshw -short`
```
The long forms of these two commands spew out exhaustive—but hard to read—output:
```
`hwinfo`
```
or
```
`lshw`
```
### CPU details
You can learn everything about your CPU through line commands. View CPU details by issuing either the **lscpu** command or its close relative **lshw**:
```
`lscpu`
```
or
```
`lshw -C cpu`
```
In both cases, the last few lines of output list all the CPU's capabilities. Here you can find out whether your processor supports specific features.
With all these commands, you can reduce verbiage and narrow any answer down to a single detail by parsing the command output with the **grep** command. For example, to view only the CPU make and model:
```
`lshw -C cpu | grep -i product`
```
To view just the CPU's speed in megahertz:
```
`lscpu | grep -i mhz`
```
or its [BogoMips][8] power rating:
```
`lscpu | grep -i bogo`
```
The **-i** flag on the **grep** command simply ensures your search ignores whether the output it searches is upper or lower case.
### Memory
Linux line commands enable you to gather all possible details about your computer's memory. You can even determine whether you can add extra memory to the computer without opening up the box.
To list each memory stick and its capacity, issue the **dmidecode** command:
```
`dmidecode -t memory | grep -i size`
```
For more specifics on system memory, including type, size, speed, and voltage of each RAM stick, try:
```
`lshw -short -C memory`
```
One thing you'll surely want to know is is the maximum memory you can install on your computer:
```
`dmidecode -t memory | grep -i max`
```
Now find out whether there are any open slots to insert additional memory sticks. You can do this without opening your computer by issuing this command:
```
`lshw -short -C memory | grep -i empty`
```
A null response means all the memory slots are already in use.
Determining how much video memory you have requires a pair of commands. First, list all devices with the **lspci** command and limit the output displayed to the video device you're interested in:
```
`lspci | grep -i vga`
```
The output line that identifies the video controller will typically look something like this:
```
`00:02.0 VGA compatible controller: Intel Corporation 82Q35 Express Integrated Graphics Controller (rev 02)`
```
Now reissue the **lspci** command, referencing the video device number as the selected device:
```
`lspci -v -s 00:02.0`
```
The output line identified as _prefetchable_ is the amount of video RAM on your system:
```
...
Memory at f0100000 (32-bit, non-prefetchable) [size=512K]
I/O ports at 1230 [size=8]
Memory at e0000000 (32-bit, prefetchable) [size=256M]
Memory at f0000000 (32-bit, non-prefetchable) [size=1M]
...
```
Finally, to show current memory use in megabytes, issue:
```
`free -m`
```
This tells how much memory is free, how much is in use, the size of the swap area, and whether it's being used. For example, the output might look like this:
```
              total        used        free     shared    buff/cache   available
Mem:          11891        1326        8877      212        1687       10077
Swap:          1999           0        1999
```
The **top** command gives you more detail on memory use. It shows current overall memory and CPU use and also breaks it down by process ID, user ID, and the commands being run. It displays full-screen text output:
```
`top`
```
### Disks, filesystems, and devices
You can easily determine whatever you wish to know about disks, partitions, filesystems, and other devices.
To display a single line describing each disk device:
```
`lshw -short -C disk`
```
Get details on any specific SATA disk, such as its model and serial numbers, supported modes, sector count, and more with:
```
`hdparm -i /dev/sda`
```
Of course, you should replace **sda** with **sdb** or another device mnemonic if necessary.
To list all disks with all their defined partitions, along with the size of each, issue:
```
`lsblk`
```
For more detail, including the number of sectors, size, filesystem ID and type, and partition starting and ending sectors:
```
`fdisk -l`
```
To start up Linux, you need to identify mountable partitions to the [GRUB][9] bootloader. You can find this information with the **blkid** command. It lists each partition's unique identifier (UUID) and its filesystem type (e.g., ext3 or ext4):
```
`blkid`
```
To list the mounted filesystems, their mount points, and the space used and available for each (in megabytes):
```
`df -m`
```
Finally, you can list details for all USB and PCI buses and devices with these commands:
```
`lsusb`
```
or
```
`lspci`
```
### Network
Linux offers tons of networking line commands. Here are just a few.
To see hardware details about your network card, issue:
```
`lshw -C network`
```
Traditionally, the command to show network interfaces was **ifconfig**:
```
`ifconfig -a`
```
But many people now use:
```
`ip link show`
```
or
```
`netstat -i`
```
In reading the output, it helps to know common network abbreviations:
**Abbreviation** | **Meaning**
---|---
**lo** | Loopback interface
**eth0** or **enp*** | Ethernet interface
**wlan0** | Wireless interface
**ppp0** | Point-to-Point Protocol interface (used by a dial-up modem, PPTP VPN connection, or USB modem)
**vboxnet0** or **vmnet*** | Virtual machine interface
The asterisks in this table are wildcard characters, serving as a placeholder for whatever series of characters appear from system to system. ****
To show your default gateway and routing tables, issue either of these commands:
```
`ip route | column -t`
```
or
```
`netstat -r`
```
### Software
Let's conclude with two commands that display low-level software details. For example, what if you want to know whether you have the latest firmware installed? This command shows the UEFI or BIOS date and version:
```
`dmidecode -t bios`
```
What is the kernel version, and is it 64-bit? And what is the network hostname? To find out, issue:
```
`uname -a`
```
### Quick reference chart
This chart summarizes all the commands covered in this article:
Display info about all hardware | **inxi -Fxz**              _\--or--_
**hwinfo --short**     _\--or--_
**lshw  -short**
---|---
Display all CPU info | **lscpu**                  _\--or--_
**lshw -C cpu**
Show CPU features (e.g., PAE, SSE2) | **lshw -C cpu | grep -i capabilities**
Report whether the CPU is 32- or 64-bit | **lshw -C cpu | grep -i width**
Show current memory size and configuration | **dmidecode -t memory | grep -i size**    _\--or--_
**lshw -short -C memory**
Show maximum memory for the hardware | **dmidecode -t memory | grep -i max**
Determine whether memory slots are available | **lshw -short -C memory | grep -i empty**
(a null answer means no slots available)
Determine the amount of video memory | **lspci | grep -i vga**
then reissue with the device number;
for example:  **lspci -v -s 00:02.0**
The VRAM is the _prefetchable_ value.
Show current memory use | **free -m**    _\--or--_
**top**
List the disk drives | **lshw -short -C disk**
Show detailed information about a specific disk drive | **hdparm -i /dev/sda**
(replace **sda** if necessary)
List information about disks and partitions | **lsblk **     (simple)      _\--or--_
**fdisk -l**   (detailed)
List partition IDs (UUIDs) | **blkid**
List mounted filesystems, their mount points,
and megabytes used and available for each | **df -m**
List USB devices | **lsusb**
List PCI devices | **lspci**
Show network card details | **lshw -C network**
Show network interfaces | **ifconfig -a**       _\--or--_
**ip link show   **_\--or--_
**netstat -i**
Display routing tables | **ip route | column -t`  `**_\--or--_
**netstat -r**
Display UEFI/BIOS info | **dmidecode -t bios**
Show kernel version, network hostname, more | **uname -a**
Do you have a favorite command that I overlooked? Please add a comment and share it.
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/9/linux-commands-hardware-information
作者:[Howard Fosdick][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/howtechhttps://opensource.com/users/sethhttps://opensource.com/users/sethhttps://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/features_solutions_command_data.png?itok=4_VQN3RK (computer screen )
[2]: http://sourceforge.net/projects/i-nex/
[3]: https://www.cpuid.com/softwares/cpu-z.html
[4]: http://sourceforge.net/projects/hardinfo.berlios/
[5]: https://userbase.kde.org/KInfoCenter
[6]: http://www.binarytides.com/linux-lshw-command/
[7]: http://www.disk-image.com/faq-bootmenu.htm
[8]: https://en.wikipedia.org/wiki/BogoMips
[9]: https://www.dedoimedo.com/computers/grub.html

View File

@ -0,0 +1,399 @@
[#]: collector: (lujun9972)
[#]: translator: (way-ww)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux commands to display your hardware information)
[#]: via: (https://opensource.com/article/19/9/linux-commands-hardware-information)
[#]: author: (Howard Fosdick https://opensource.com/users/howtechhttps://opensource.com/users/sethhttps://opensource.com/users/sethhttps://opensource.com/users/seth)
Linux 命令行显示硬件信息
======
通过命令行获取电脑硬件详细信息
![computer screen ][1]
你可能会有很多的原因需要查清计算机硬件的详细信息。 例如, 你需要修复某些问题并在论坛上发出请求, 人们可能会立即询问你的计算机具体的信息。 或者当你想要升级计算机配置时, 你需要知道现有的硬件型号和能够升级的型号。 这些都需要查询你的计算机具体规格信息。
最简单的方法是使用标准的 Linux GUI 程序之一:
* [i-nex][2] 收集硬件信息并且像 Windows 下流行的 [CPU-Z][3] 方式显示。
* [HardInfo][4] 显示硬件具体信息甚至包括一组八个的流行的基础程序你可以用它们评估你的系统性能。
* [KInfoCenter][5] 和 [Lshw][6] 也能够显示硬件的详细信息并且可以从许多软件仓库中获取。
或者, 你也可以拆开电脑外盒去阅读硬盘, 内存和其他设备上的标签信息。 或者你可以在系统启动时, 按下相应的按键进入 UEFI 和 BIOS 界面获得信息。 这俩种方式都会向你显示硬件信息但省略软件信息。
你也可以使用命令行获取硬件信息。 等一下… 这听起来有些困难。 为什么你会要这样做?
有时候通过使用一条针对性强的命令可以很轻松的找到特定信息。 也可能你没有可用的 GUI 程序或者只是不想安装这样的程序。
使用命令行的主要原因可能是编写脚本。 无论你是使用 Linux shell 还是其他编程语言来编写脚本通常都需要使用命令行。
很多检测硬件信息的命令行都需要使用 root 权限。 所以要么切换到 root 用户, 要么使用 **sudo** 在普通用户状态下发出命令:
```
sudo <the_line_command>
```
并按提示输入密码。
这篇文章介绍了很多有用的系统发现命令。 文章最后的快速查询表对它们作出了总结。
### 硬件概述
下面几条命令可以全面概述计算机硬件信息。
**inxi** 命令能够列出包括 CPU 图形, 音频, 网络, 驱动, 分区, 传感器等详细信息。 当论坛里的人尝试帮助其他人解决问题的时候, 他们常常询问此命令的输出。 这是解决问题的标准诊断程序:
```
inxi -Fxz
```
**-F** 参数意味着你将得到完整的输出, **x** 增加细节信息, **z** 参数隐藏像 MAC 和 IP 等私人身份信息。
**hwinfo** 和 **lshw** 命令以不同的格式显示大量相同的信息:
```
hwinfo --short
```
```
lshw -short
```
这俩条命令的长格式输出非常详细但也有点难以阅读:
```
hwinfo
```
```
lshw
```
### CPU 详细信息
通过命令你可以了解关于你的 CPU 的任何信息。 使用 **lscpu** 命令或与它相近的 **lshw** 命令查看 CPU 的详细信息:
```
lscpu
```
```
lshw -C cpu
```
在这俩个例子中, 输出的最后几行都列出了所有 CPU 的功能。 你可以查看你的处理器是否支持特定的功能。
使用这些命令的时候, 你可以通过使用 **grep** 命令过滤复杂的信息, 并缩小所需信息范围。 例如, 只查看 CPU 品牌和型号:
```
lshw -C cpu | grep -i product
```
仅查看 CPU 的速度(兆赫兹):
```
lscpu | grep -i mhz
```
或其 [BogoMips][8] 额定功率:
```
lscpu | grep -i bogo
```
**grep** 命令的 **-i** 参数代表搜索结果忽略大小写。
### 内存
Linux 命令行使你能够收集关于你的计算机内存的所有可能的详细信息。 你甚至可以不拆开电脑外壳就能确定是否可以为计算机添加额外的内存条。
使用 **dmidecode** 命令列出每根内存条和其容量:
```
dmidecode -t memory | grep -i size
```
使用以下命令获取系统内存更多的信息, 包括类型, 容量, 速度, 和电压:
```
lshw -short -C memory
```
你肯定想知道的一件事是你的计算机可以安装的最大内存:
```
dmidecode -t memory | grep -i max
```
现在检查一下计算机是否有空闲的插槽可以插入额外的内存条。 你可以通过使用命令在不打开电脑的情况下就做到:
```
lshw -short -C memory | grep -i empty
```
输出为空则意味着所有的插槽都在使用中。
确定你的电脑拥有多少显卡内存需要下面的命令。 首先使用 **lspci** 列出所有设备信息然后过滤出你想要的显卡设备信息:
```
lspci | grep -i vga
```
视频控制器的设备号输出信息通常如下:
```
`00:02.0 VGA compatible controller: Intel Corporation 82Q35 Express Integrated Graphics Controller (rev 02)`
```
现在再使用 **lspci** 命令加上视频设备号:
```
lspci -v -s 00:02.0
```
输出信息中 prefetchable 那一行显示了系统中的显卡内存大小:
```
...
Memory at f0100000 (32-bit, non-prefetchable) [size=512K]
I/O ports at 1230 [size=8]
Memory at e0000000 (32-bit, prefetchable) [size=256M]
Memory at f0000000 (32-bit, non-prefetchable) [size=1M]
...
```
最后使用下面的命令展示当前内存使用量(兆字节):
```
free -m
```
这条命令告诉你多少内存是空闲的, 多少命令正在使用中以及交换内存的大小和是否正在使用。 例如, 输出信息如下:
```
              total        used        free     shared    buff/cache   available
Mem:          11891        1326        8877      212        1687       10077
Swap:          1999           0        1999
```
**top** 命令为你提供内存使用更加详细的信息。 它显示了当前全部内存和 CPU 使用情况并按照进程 ID 用户 ID及正在运行的命令细分。 同时这条命令也是全屏输出:
```
top
```
### 磁盘文件系统和设备
你可以轻松确定有关磁盘, 分区, 文件系统和其他设备信息。
显示每个磁盘设备的描述信息:
```
lshw -short -C disk
```
通过以下命令获取任何指定的 SATA 磁盘详细信息, 例如其型号, 序列号以及支持的模式和扇区数量等:
```
hdparm -i /dev/sda
```
当然, 如果需要的话你应该将 **sda** 替换成 **sdb** 或者其他设备号。
要列出所有磁盘及其分区和大小, 请使用以下命令:
```
lsblk
```
使用以下命令获取更多有关扇区数量, 大小, 文件系统 ID 和 类型以及分区开始和结束扇区:
```
fdisk -l
```
要启动 Linux 你需要确定[GRUB][9] 引导程序的安装分区。 你可以使用 **blkid** 命令找到此信息。它列出了每个分区的唯一标识符(UUID) 及其文件系统类型(例如 ext3 或 ext4):
```
blkid
```
使用以下命令列出已挂载的文件系统和它们的挂载点以及已用的空间和可用的空间(兆字节为单位):
```
df -m
```
最后, 你可以列出所有的 USB 和 PCI 总线以及其他设备的详细信息:
```
lsusb
```
```
lspci
```
### 网络
Linux 提供大量的网络相关命令, 下面只是几个例子。
查看你的网卡硬件详细信息:
```
lshw -C network
```
**ifconfig** 是显示网络接口的传统命令:
```
ifconfig -a
```
但是现在很多人们使用:
```
ip link show
```
```
netstat -i
```
在阅读输出时, 了解常见的网络缩写十分有用:
**缩写** | **含义**
---|---
**lo** | 回环接口
**eth0** or **enp*** | 以太网接口
**wlan0** | 无线网接口
**ppp0** | 点对点协议接口由拨号调制解调器PPTP VPN连接或者 USB 调制解调器使用)
**vboxnet0** or **vmnet*** | 虚拟机网络接口
表中的星号是通配符, 用作系统间出现的任何字符的占位符。
使用以下命令显示默认网关和路由表:
```
ip route | column -t
```
```
netstat -r
```
### 软件
让我们以显示最底层软件详细信息的俩条命令来结束。 例如, 如果你想知道是否安装了最新的固件该怎么办?这条命令显示了 UEFI 或 BIOS 的日期和版本:
```
dmidecode -t bios
```
内核版本是多少以及它是 64 位的吗? 网络主机名是什么? 使用下面的命令查出结果:
```
uname -a
```
### 快速查询表
显示所有硬件信息 | **inxi -Fxz****hwinfo --short** 或 **lshw  -short**
---|---
CPU 信息 | **lscpu** 或 **lshw -C cpu**
显示 CPU 功能(例如 PAE, SSE2) | **lshw -C cpu \| grep -i capabilities**
报告 CPU 位数 | **lshw -C cpu \| grep -i width**
显示当前内存大小和配置 | **dmidecode -t memory \| grep -i size** 或 **lshw -short -C memory**
显示硬件支持的最大内存 | **dmidecode -t memory \| grep -i max**
确定是否有空闲内存插槽 | **lshw -short -C memory \| grep -i empty**(输出为空表示没有可用插槽)
确定显卡内存数量 | **lspci \| grep -i vga** 然后指定设备号再次使用; 例如:  **lspci -v -s 00:02.0** 显卡内存数量就是  prefetchable 的值
显示当前内存使用情况 | **free -m** 或 **top**
列出磁盘驱动器 | **lshw -short -C disk**
显示指定磁盘驱动器的详细信息 | **hdparm -i /dev/sda**(需要的话替换掉 **sda** )
列出磁盘和分区信息 | **lsblk**  (简单)   或 **fdisk -l**   (详细)
列出分区 IDs (UUIDs) | **blkid**
列出已挂载文件系统挂载点以及已用和可用空间 | **df -m**
列出 USB 设备 | **lsusb**
列出 PCI 设备 | **lspci**
显示网卡详细信息 | **lshw -C network**
显示网络接口 | **ifconfig -a** 或 **ip link show** 或 **netstat -i**
显示路由表 | **ip route \| column -t** 或 **netstat -r**
显示 UEFI/BIOS 信息 | **dmidecode -t bios**
显示内核版本网络主机名等 | **uname -a**
你有喜欢的命令被我忽略掉的吗? 请添加评论分享给大家。
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/9/linux-commands-hardware-information
作者:[Howard Fosdick][a]
选题:[lujun9972][b]
译者:[way-ww](https://github.com/way-ww)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/howtechhttps://opensource.com/users/sethhttps://opensource.com/users/sethhttps://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/features_solutions_command_data.png?itok=4_VQN3RK (computer screen )
[2]: http://sourceforge.net/projects/i-nex/
[3]: https://www.cpuid.com/softwares/cpu-z.html
[4]: http://sourceforge.net/projects/hardinfo.berlios/
[5]: https://userbase.kde.org/KInfoCenter
[6]: http://www.binarytides.com/linux-lshw-command/
[7]: http://www.disk-image.com/faq-bootmenu.htm
[8]: https://en.wikipedia.org/wiki/BogoMips
[9]: https://www.dedoimedo.com/computers/grub.html