有几种方法可以通过 Linux 命令行列出系统中存在的所有硬盘驱动器。
记住一个 硬盘 可以物理连接、虚拟连接甚至模拟(例如 example:当您使用 EMC、Sun 或 IBM 等存储设备时)。
以下是一些可以列出硬盘驱动器的不同命令,请记住还有其他命令,但这些可能是最常用且易于完成的工作。
在 Linux 中列出硬盘驱动器
请注意,其中一些命令实际上是磁盘分区工具,列出磁盘分区是它们的功能之一。
让我们看看可以使用哪些命令在 Linux 中显示磁盘信息。
1.df
Linux 中的 df 命令可能是最常用的命令之一。 它列出了实际的“磁盘空间使用情况”,它可以为您提供有关整个系统中正在使用哪些硬盘(或当前磁盘空间)的信息。
最常见的使用方式是使用 -h 参数,意思是“人类可读”(因为我们不是机器,对吧?):
[email protected]:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 3.5M 1.6G 1% /run
/dev/sda2 468G 204G 242G 46% /
tmpfs 7.8G 109M 7.7G 2% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/loop0 7.5M 7.5M 0 100% /snap/canonical-livepatch/54
/dev/loop1 90M 90M 0 100% /snap/core/6034
/dev/loop2 5.0M 5.0M 0 100% /snap/canonical-livepatch/50
/dev/loop4 90M 90M 0 100% /snap/core/6130
/dev/loop3 4.8M 4.8M 0 100% /snap/canonical-livepatch/49
/dev/loop5 89M 89M 0 100% /snap/core/5897
/dev/sda1 511M 6.1M 505M 2% /boot/efi
tmpfs 1.6G 16K 1.6G 1% /run/user/121
tmpfs 1.6G 44K 1.6G 1% /run/user/1000
如您所见,第一列是当前逻辑名称(或您可以在系统中找到的名称),第二列是每个逻辑的大小,第三列是当前使用的数量(以字节为单位) ,第四列是当前每个可用的使用量(以字节为单位),第五列是使用量(以%计),第六列也是最后一列是它在 Linux 系统中的物理安装位置。
2.磁盘
磁盘 是 sysops 中的另一个常见选项。 它目前列出了您系统中的不同分区(与硬盘驱动器有关,因为一个硬盘驱动器可以分为几个分区)。
[email protected]:~$ fdisk -l
Disk /dev/loop0: 7.5 MiB, 7811072 bytes, 15256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 89.5 MiB, 93818880 bytes, 183240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 4.9 MiB, 5148672 bytes, 10056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop3: 4.7 MiB, 4919296 bytes, 9608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop4: 89.5 MiB, 93835264 bytes, 183272 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop5: 88.2 MiB, 92483584 bytes, 180632 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 129F4EE6-2A54-4639-BFCA-2CC09DFC8566
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 1000214527 999163904 476.4G Linux filesystem
这将返回全部空间量(以 GB 或 MB 为单位)、全部字节数和每个分区的全部扇区数,作为总结,它还为您提供了开始和结束扇区、磁盘空间量(以字节为单位)和分区类型。
提示: 通常一个 SATA 磁盘标有 sd。
3. lsblk
这个稍微复杂一点,但可以完成工作,因为它列出了所有块设备。 它将为您提供所有设备的非常简单的列表:
[email protected]:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 7.5M 1 loop /snap/canonical-livepatch/54
loop1 7:1 0 89.5M 1 loop /snap/core/6034
loop2 7:2 0 4.9M 1 loop /snap/canonical-livepatch/50
loop3 7:3 0 4.7M 1 loop /snap/canonical-livepatch/49
loop4 7:4 0 89.5M 1 loop /snap/core/6130
loop5 7:5 0 88.2M 1 loop /snap/core/5897
sda 8:0 0 477G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 476.4G 0 part /
它可能比其他更直观,因为它甚至以可视方式显示每个磁盘的分区(如 example 多于)。 它还提供有关每个分区和磁盘的总大小以及每个分区和磁盘的物理位置的信息。 当您需要安装要使用的东西(如 U 盘或类似设备)时,这非常常用,因此您可以知道它在哪里以便继续安装它。
4.cfdisk
磁盘 可能是 GUI(图形用户界面)中最先进的一个,因为它绝对是可视化和交互式的。 它首先允许列出系统中的所有磁盘/分区,但它也允许您通过选择它们然后应用诸如“删除”、“调整大小”、“类型”(更改分区类型)和“写入”等操作来管理它们” 对分区所做的更改。
它还为您提供有关每个分区和磁盘的非常友好的信息,因为它为您提供每个分区柱面的开始和结束位置、每个分区使用的扇区数量以及每个分区的完整大小及其类型。 它不会给你 example 使用多少或免费使用多少。
5.分开
这与前面提到的类似,它列出了所有分区并允许管理它们。 它的主要区别在于它还通知您硬盘的品牌和型号,甚至其中使用的连接类型(scsi、sata 等)和总磁盘大小。
[email protected]:~$ sudo parted -l
Model: ATA LITEON CV1-8B512 (scsi)
Disk /dev/sda: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 538MB 537MB fat32 EFI System Partition boot, esp
6.sfdisk
这与 fdisk 非常相似,但是 磁盘 允许您查看物理卷和逻辑卷,还可以为您提供实际物理卷分区的“摘要”,包括柱面(开始和结束)、扇区、大小和类型。
可能“s”代表“super”,因为它是一个具有超能力的 fdisk:
[email protected]:~$ sudo sfdisk -l
Disk /dev/loop0: 88.2 MiB, 92483584 bytes, 180632 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 4.7 MiB, 4919296 bytes, 9608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 4.9 MiB, 5148672 bytes, 10056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop3: 89.5 MiB, 93818880 bytes, 183240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop4: 7.5 MiB, 7811072 bytes, 15256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop5: 89.5 MiB, 93835264 bytes, 183272 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 129F4EE6-2A54-4639-BFCA-2CC09DFC8566
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 1000214527 999163904 476.4G Linux filesystem
这些命令应该允许您至少查看系统中有哪些逻辑卷、分区和硬盘驱动器,并出于您需要的任何原因使用这些信息,这只是为了了解更多信息或操作其中任何一个。
这些命令中的大多数还为您提供了随意修改和操作分区的管理功能,因此请确保负责任地使用它们。
如果您喜欢检查系统信息,请阅读有关在 Linux 命令行中获取处理器信息的文章。
如果您有任何问题或建议,请在评论部分告诉我。