linux 终端80列_如何从Linux终端列出计算机的设备

linux 终端80列

linux 终端80列

Linux PC showing a shell prompt
Fatmawati Achmad Zaenuri/Shutterstock.com Fatmawati Achmad Zaenuri / Shutterstock.com

Find out exactly what devices are inside your Linux computer or connected to it. We’ll cover 12 commands for listing your connected devices.

准确找出您的Linux计算机内部或已连接了哪些设备。 我们将介绍12个用于列出您已连接设备的命令。

为什么要十二个命令? (Why 12 Commands?)

However many ways there are to skin a cat, I’d be willing to bet that there are more ways to list the devices that are connected to, or housed inside of, your Linux computer. We’re going to show you 12 of them. And that’s not all of them!

不管用哪种方法来给猫咪剥皮,我都想打赌,还有更多方法可以列出连接到Linux计算机或安装在Linux计算机内部的设备。 我们将向您展示其中的12个。 而且还不是全部!

Inevitably, there’s a lot of overlap in the information that you can get out of these commands, so why bother describing this many of them?

不可避免地,您会从这些命令中获得很多信息重叠,那么为什么还要麻烦地描述其中的许多命令呢?

Well, for one thing, the variations in content and detail make them sufficiently different that some people will prefer one method over another. The output format of one command might lend itself particularly well to a specific use case. The format of another command might be ideally suited to its being piped through grep, or another method of further processing.

好吧,一方面,内容和细节的变化使它们有足够的差异,以至于有些人会更喜欢一种方法。 一个命令的输出格式可能非常适合于特定的用例。 另一个命令的格式可能非常适合通过grep或另一种进一步处理方法通过管道传递。

Primarily though, it is to make the article as general as possible. Rather than decide which commands are going to be of interest or use to our readership, we’d rather provide a broad sample of the commands that are available and have our readers choose which ones they will use and which ones they will leave untouched.

不过,主要是使文章尽可能通用。 与其确定哪些命令对我们的读者感兴趣或有用,不如提供可用命令的广泛示例,让我们的读者选择将使用的命令,以及将不受影响的命令。

需要某些安装 (Some Installation Required)

Most of these commands are included within your Linux distribution by default. Ubuntu, Fedora, and Manjaro were used as a representative sample of distributions from the main branches of the Debian, Red Hat and Arch families.

默认情况下,这些命令大多数都包含在Linux发行版中。 Ubuntu,Fedora和Manjaro被用作Debian,Red Hat和Arch系列主要分支的代表性发行样本。

All three distributions needed to install procinfo, which provides the lsdev command. The lsscsi command also needed to be installed on all three.

安装提供lsdev命令的procinfo所需的所有三个发行版。 还必须在所有这三个目录上安装lsscsi命令。

To install lsdev and lsscsi, use these commands.

要安装lsdevlsscsi ,请使用以下命令。

Ubuntu:

Ubuntu:

sudo apt-get install procinf
sudo apt-get install lsscsi
sudo apt-get install lsscsi in a terminal window
sudo apt-get install procinf in a terminal window

Fedora:

软呢帽:

sudo dnf install procinfo
sudo dnf install lsscsi
sudo dnf install procinfo in a terminal window
sudo dnf install lsscsi in a terminal window

Manjaro

万家郎

sudo pacman -Syu procinfo
sudo pacman -Syu lsscsi
sudo pacman -Syu lsscsi in a terminal window
sudo pacman -Syu procinfo in a terminal window

Surprisingly, Manjaro—famous for being a bare-bones type of distribution—was the distribution that had most of the commands we’re going to look at pre-installed.

出乎意料的是,Manjaro(以一种简直的发行版而闻名)是具有预安装的大多数命令的发行版。

Ubuntu and Fedora needed hwinfo installing, and Fedora also required lshw and hdparm installing.

Ubuntu和Fedora需要安装hwinfo ,Fedora也需要安装lshwhdparm

Ubuntu:

Ubuntu:

sudo apt-get install hwinfo
sudo apt-get install hwinfo in a terminal window

Fedora:

软呢帽:

sudo dnf install hwinfo
sudo dnf install lshw
sudo dnf install hdparm
sudo dnf install hwinfo in a terminal window
sudo dnf install hwinfo in a terminal window
sudo dnf install lshw in a terminal window

1. mount命令 (1. The mount Command)

The mount command is used to mount filesystems.

mount命令用于挂载文件系统

But issuing the command with no parameters causes it to list all of the mounted filesystems, as well as the devices they are located on. So we can use this as a means of discovering those devices.

但是发出不带参数的命令会导致它列出所有已挂载的文件系统以及它们所在的设备。 因此,我们可以将其用作发现那些设备的方法。

mount
mount in a terminal window

The output from mount can be longer than you expected, especially if you have used the snap method to install software. Each time you use snap you acquire another pseudo-filesystem and these get listed by mount . Of course, these do not have physical devices associated with them, so they are just obscuring the real picture.

mount的输出可能比您预期的长,特别是如果您已使用snap方法安装软件。 每次您使用snap都会获取另一个伪文件系统,这些文件将由mount列出。 当然,这些设备没有与之关联的物理设备,因此它们只是掩盖了真实情况。

output from mount in a terminal window

If you spot a real filesystem in the listing sitting on a hard drive, we can isolate it with grep.

如果您在硬盘上的清单中发现了一个真实的文件系统,则可以使用grep将其隔离。

Hard drives are identified by name, usually called “sd” followed by a letter starting at “a” for the first drive, “b” for the second drive and so one.  Partitions are identified by adding a 1 for the first partition and 2 for the second partition, and so on.

硬盘由名称标识,通常称为“ sd”,后跟一个字母,第一个驱动器的字母为“ a”,第二个驱动器的字母为“ b”,以此类推。 通过为第一个分区添加1并为第二个分区添加2来标识分区,依此类推。

So the first hard drive would be sda, and the first partition on that drive would be called sda1. Hard drives are interfaced through special device files (called block files) in /dev and then mounted somewhere on the filesystem tree.

因此,第一个硬盘驱动器将是sda,而该驱动器上的第一个分区将被称为sda1。 硬盘驱动器通过/ dev中的特殊设备文件(称为块文件)进行接口,然后安装在文件系统树上的某个位置。

This command used grep to filter out the details of any drive that begins with “sd”.

此命令使用grep过滤掉以“ sd”开头的任何驱动器的详细信息。

mount | grep /dev/sd
mount | grep /dev/sd in a terminal window

The output contains the single hard drive in the machine that was used to research this article.

输出包含用于研究本文的计算机中的单个硬盘驱动器。

mount output in a terminal window

The response from mount tells us that drive /dev/sda is mounted at / (the root of the filesystem tree) and it has an ext4 filesystem. The “rw” indicates it has been mounted in read-write mode

mount的响应告诉我们,驱动器/ dev / sda已安装在/(文件系统树的根目录)上,并且具有ext4文件系统。 “ rw”表示它已以读写模式安装

Relatime is the scheme used by the file timestamp updating routines. The access time is not written to the disk unless either the modified time (mtime) or change time (ctime) of a file is more recent than the last access time, or the access time (atime) is older than a system-defined threshold. This greatly reduces the number of disk updates that need to take place for frequently accessed files.

Relatime是文件时间戳更新例程使用的方案。 除非文件的修改时间(mtime)或更改时间(ctime)比最近的访问时间新,或者访问时间(atime)早于系统定义的阈值,否则访问时间不会写入磁盘。 。 这大大减少了频繁访问文件所需的磁盘更新次数。

The “errors=remount-ro” indicates that if there are sufficiently severe errors, the filesystem will be remounted in read-only mode.

“ errors = remount-ro”表示如果存在足够严重的错误,文件系统将以只读模式重新安装。

To be able to scroll through the output from mount and more easily spot the filesystems that are mounted on devices, pipe the output from mount through less .

为了能够滚动查看来自mount的输出并更容易地发现安装在设备上的文件系统,请通过less将来自mount的输出进行管道传输。

mount | less
mount | less in a terminal window

Scroll through the output until you see filesystems that are connected to /dev special files.

滚动浏览输出,直到看到连接到/ dev特殊文件的文件系统。

mount [piped through less in a terminal window

2. lsblk命令 (2. The lsblk Command)

The lsblk command lists the block devices, their mount point, and other information. Type lsblk at a command line:

lsblk命令列出了块设备 ,它们的安装点和其他信息。 在命令行中lsblk

lsblk
lsblk in a terminal window

The output shows:

输出显示:

  • Name: the name of the block device

    名称 :块设备的名称

  • Maj:Min: The major number shows the device type. The minimum number is the number of the current device out of the list of devices of that type. 7:4, for example, means loop device number 4.

    Maj:Min :主数字显示设备类型。 最小数量是该类型设备列表中当前设备的数量。 例如,7:4表示回路设备编号4。

  • RM: Whether the device is removable or not. 0 means no, 1 means yes.

    RM :设备是否可移动。 0表示否,1表示是。

  • Size is the capacity of the device.

    大小是设备的容量。

  • RM: Whether the device is read-only or not. 0 means no, 1 means yes.

    RM :设备是否为只读。 0表示否,1表示是。

  • Type: The type of the device, for example, loop, dir (directory), disk, rom (CD ROM), and so on.

    类型 :设备的类型,例如,循环,目录(目录),磁盘,只读光盘(CD ROM)等。

  • Mountpoint: Where the filesystem of the device is mounted.

    Mountpoint :设备文件系统的安装位置。

lsblk output in a terminal window

To de-clutter the output and remove the loop devices, we can use the -e (exclude) option and provide the number of the type of devices we wish to ignore.

为了使输出杂乱无章并删除循环设备,我们可以使用-e (排除)选项并提供我们希望忽略的设备类型的数量。

This command will cause lsblk to ignore the loop (7) and cd room (11) devices.

此命令将导致lsblk忽略循环(7)和cd room(11)设备。

lsblk -e 7,11
lsblk -e 7,11 in a terminal window

The results now only contain the hard drive sda.

结果现在仅包含硬盘驱动器sda。

lsblk output in a terminal window

3. df命令 (3. The df Command)

The df command reports on drive capacities and used and free space.

df命令报告驱动器容量以及已用和可用空间

Type df on the command line and press Enter.

在命令行上输入df ,然后按Enter键。

df
df in a terminal window

The output table shows:

输出表显示:

  • Fileystem: The name of this filesystem.

    Fileystem :此文件系统的名称。

  • 1K-Blocks: The number of 1K blocks that are available on this filesystem.

    1K块 :此文件系统上可用的1K块数。

  • Used: The number of 1K blocks that have been used on this file system.

    已使用 :此文件系统上已使用的1K块数。

  • Available: The number of 1K blocks that are unused on this file system.

    可用 :此文件系统上未使用的1K块数。

  • Use%: The amount of space used in this file system given as a percentage.

    Use% :此文件系统中使用的空间量(以百分比表示)。

  • File: The filesystem name, if specified on the command line.

    File :文件系统名称,如果在命令行上指定。

  • Mounted on: The mount point of the filesystem.

    挂载 :文件系统的挂载点。

output from df in a terminal window

To remove unwanted entries from the output, use the -x (exclude) option. This command will prevent the loop device entries from being listed.

要从输出中删除不需要的条目,请使用-x (排除)选项。 此命令将阻止列出循环设备条目。

df -x squashfs
df -x squashfs in a terminal window

The compact output is much easier to parse for the important information.

紧凑的输出更容易解析重要信息。

df output in a terminal window

4. fdisk命令 (4. The fdisk Command)

The fdisk command is a tool designed to manipulate the disk partition table, but it can be used to view information as well. We can use this to our advantage when we are investigating the devices in a computer.

fdisk命令是用于处理磁盘分区表的工具,但也可以用来查看信息 。 在研究计算机中的设备时,我们可以利用此优势。

We will use the -l (list) option to list the partition tables. Because the output might be very long, we will pipe the output from fdisk through less. Because fdisk has the potential to alter disk partition tables, we must use sudo.

我们将使用-l (列表)选项列出分区表。 由于输出可能会很长,我们会从管道输出fdisk通过less 。 由于fdisk可能会更改磁盘分区表,因此必须使用sudo

sudo fdisk -l
fdisk -l in a terminal window

By scrolling through less you will be able to identify the hardware devices. Here is the entry for hard drive sda. This is a physical hard drive of 10 GB.

通过less滚动less您将能够识别硬件设备。 这是硬盘驱动器sda的条目。 这是10 GB的物理硬盘驱动器。

output from fdisk in a terminal window

Now that we know the identity of one of the hardware devices we can ask fdisk to report on that item alone.

现在我们知道了其中一个硬件设备的身份,我们可以要求fdisk仅报告该项目。

sudo fdisk -l /dev/sda
sudo fdisk -l /dev/sda in a terminal window

We get an output of considerably reduced length.

我们得到的输出长度大大减少了。

output of fdisk in a terminal window

5. / proc文件 (5. The /proc Files)

The pseudo-files in /proc can be viewed to obtain some system information. The file we will look at is /proc/mounts, which will give us some information regarding the mounted filesystems. We will use nothing grander than cat  to view the file.

可以查看/ proc中的伪文件以获得一些系统信息。 我们将查看的文件是/ proc / mounts,它将为我们提供有关已挂载文件系统的一些信息。 我们将使用比cat更宏大的功能来查看文件。

cat /proc/mounts
cat /proc/mounts  in a terminal window

The listing shows the special device file in /dev that is used to interface to the device and the mount point on the filesystem tree.

清单显示了/ dev中的特殊设备文件,该文件用于连接设备和文件系统树上的安装点。

output from cat /proc/mounts in a terminal window

We can refine the listing by using grep to look for entries with /dev/sd in them. This will filter out the physical drives.

我们可以使用grep查找其中包含/ dev / sd的条目来优化列表。 这将过滤掉物理驱动器。

cat /proc/mounts | grep /dev/sd
cat /proc/mounts | grep /dev/sd in a terminal window

This gives us a much more manageable report.

这为我们提供了更易于管理的报告。

output from cat /proc/mounts in a terminal window

We can be slightly more inclusive by using grep to look for devices that have  /dev/sd and /dev/sr special device files. This will include hard drives and the CD ROM for this machine.

通过使用grep查找具有/ dev / sd和/ dev / sr特殊设备文件的设备,我们可以更具包容性。 这将包括本机的硬盘驱动器和CD ROM。

cat /proc/partitions | grep s[rd]
cat /proc/partitions | grep s[rd] in a terminal window

There are now two devices and one partition included in the output.

现在,输出中包括两个设备和一个分区。

output from cat /proc/mounts in a terminal window

6. lspci命令 (6. The lspci Command)

The lspci command lists all of the PCI devices in your computer.

lspci命令列出计算机中的所有PCI设备

lspci
lspci in a terminal window

The information provided is:

提供的信息是:

  • Slot: The slot the PCi device is fitted in

    插槽 :PCi设备安装的插槽

  • Class: The class of the device.

    类别 :设备的类别。

  • Vendor name: The name of the manufacturer.

    供应商名称 :制造商的名称。

  • Device name: The name of the device.

    设备名称设备名称

  • Subsystem: Subsystem vendor name (if the device has a subsystem).

    子系统 :子系统供应商名称(如果设备具有子系统)。

  • Subsystem name: If the device has a subsystem.

    子系统名称 :如果设备具有子系统。

  • Revision number: The version number of the device

    版本号 :设备的版本号

  • Programming interface: The programming interface, if the device provides one.

    编程接口 :编程接口(如果设备提供的话)。

lspci output in a terminal window

7. lsusb命令 (7. The lsusb Command)

The lsusb command will list devices that are connected to USB ports on your computer as well as USB enabled devices that are built into your computer.

lsusb命令将列出连接到计算机USB端口的设备以及计算机中内置的支持USB的设备。

lsusb
lsusb in a terminal window

This test computer has a Canon scanner attached to it as USB device 5, and an external USB drive as USB device 4. Devices 3 and 1 are internal USB interface handlers.

该测试计算机具有一个佳能扫描仪(作为USB设备5)和一个外部USB驱动器作为USB设备4(设备)。设备3和1是内部USB接口处理程序。

USB devices listed in a terminal window

You can receive a more verbose listing by using the -v (verbose) option, and even more verbose version by using -vv.

使用-v (详细)选项可以收到更详细的列表,使用-vv可以得到更详细的列表。

8. lsdev命令 (8. The lsdev Command)

The lsdev command displays information on all of the installed devices.

lsdev命令显示有关所有已安装设备的信息

This command generates a lot of output, so we’re going to pipe it through less.

该命令产生大量输出,因此我们将通过更少的管道进行输出。

lsdev | less
lsdev | less in a terminal window

There are many hardware devices listed in the output.

输出中列出了许多硬件设备。

lsdev output piped through less in a terminal window

9. lshw命令 (9. The lshw Command)

The lshw command lists the devices connected to your computer. This is another command with a lot of output. On the test computer, there were over 260 lines of information generated. We’ll pipe it through less once more.

lshw命令列出了连接到计算机的设备 。 这是另一个输出很多的命令。 在测试计算机上,生成了260行以上的信息。 我们将再次通过less管道。

Note that you need to use sudo with lshw to get the most out of it. If you don’t, it won’t be able to access all devices.

请注意,您需要将sudolshw结合使用以lshw利用它。 如果不这样做,它将无法访问所有设备。

sudo lshw | less
sudo lshw | less in a terminal window

Here is the entry for the CD ROM with a SCSI interface. As you can see the information provided for each device is very detailed. lshw reads most of its information from the various files in /proc.

这是带有SCSI接口的CD ROM的条目。 如您所见,为每个设备提供的信息非常详细。 lshw从/ proc中的各个文件中读取大多数信息。

output of lshw in less in a terminal window

If you want a shorter, less detailed output, you can use the --short option.

如果您想要更短,更不详细的输出,可以使用--short选项。

10. lsscsi命令 (10. The lsscsi Command)

As you would imagine by now, the lsscsi command lists the SCSI devices connected to your computer.

就像您现在想像的那样, lsscsi命令列出了连接到计算机的SCSI设备

lsscsi
lsscsi in a terminal window

Here are the SCSI devices connected to this test machine.

这是连接到该测试计算机的SCSI设备。

lsscsi output in a terminal widnow

11. dmidecode命令 (11. The dmidecode Command)

The dmidecode commands decodes the Desktop Management Interface (DMI) tables, and extracts information related to the hardware connected to the computer, and inside the computer.

dmidecode命令对桌面管理接口(DMI)表进行解码,并提取与连接到计算机以及计算机内部的硬件有关的信息。

The DMI is also sometimes referred to as the SMBIOS (the System Management Basic Input/Output System) although they are really two different standards.

尽管DMI实际上是两个不同的标准,但有时也称为SMBIOS(系统管理基本输入/输出系统)。

Again, we’ll pipe this through less.

同样,我们将通过less传递。

dmidecode | less
dmidecode output in a terminal window

The dmidecode command can report on over 40 different hardware types.

dmidecode命令可以报告40多种不同的硬件类型。

12. hwinfo命令 (12. The hwinfo Command)

The hwinfo command is the most verbose of them all. When we say that you need to pipe something through less, this time it isn’t optional. On the test computer, it generated 5850 lines of output!

hwinfo命令是所有命令中最详细的命令。 当我们说您需要通过less传递内容时,这不是可选的。 在测试计算机上,它产生了5850行输出!

You can start things off gently by including the --short option.

您可以通过包含--short选项来轻松地开始工作。

hwinfo --short
hwinfo --short in a terminal window

If you really need to see the finest-grained detail, repeat this and omit the --short option.

如果您确实需要查看最详细的细节,请重复此操作并忽略--short选项。

output from hwinfo in less in a terminal window

结语 (Wrap It Up)

So, here’s our dozen ways to investigate the devices within, or attached to, your computer.

因此,这是我们研究计算机内部或连接到计算机的设备的十二种方法。

Whatever your particular interest in hunting down this hardware may be, there’ll be a method in this list that will enable you to find what you need.

无论您对寻找该硬件有什么特别的兴趣,此列表中都会有一种方法可以使您找到所需的东西。

翻译自: https://www.howtogeek.com/426199/how-to-list-your-computers-devices-from-the-linux-terminal/

linux 终端80列

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值