Linux 下,可使用“df -h”查看硬盘使用情况,“lsblk
Linux系统中,查看硬盘信息是一项常见的操作,无论是了解硬盘的容量、使用情况,还是诊断硬件问题,都可能需要查看硬盘的相关信息,以下是几种在Linux下查看硬盘信息的常用方法:
使用lsblk
命令
lsblk
(list block devices)命令用于列出所有块设备的信息,包括硬盘、分区等,它以树状结构显示设备之间的关系,非常直观。
示例输出:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 232.9G 0 disk ├─sda1 8:1 0 232.9G 0 part /home └─sda2 8:2 0 1K 0 part sdb 8:16 0 149.1G 0 disk └─sdb1 8:17 0 149.1G 0 part /mnt/data
解释:
NAME
:设备名称。MAJ:MIN
:主设备号和次设备号。RM
:是否可移除(1表示可移除,0表示不可移除)。SIZE
:设备大小。RO
:是否只读(1表示只读,0表示可读写)。TYPE
:设备类型(disk表示硬盘,part表示分区)。MOUNTPOINT
:挂载点。
使用fdisk
命令
fdisk
命令主要用于磁盘分区,但也可以用来查看硬盘的分区表信息。
示例输出:
$ sudo fdisk -l Disk /dev/sda: 232.9 GiB, 250000000000 bytes, 488397168 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: dos Disk identifier: 0x12345678 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 488397167 488395120 232.9G 83 Linux /dev/sda2 488397168 488397311 144 72K 82 Linux swap / Solaris
解释:
Disk /dev/sda
:设备名称。9 GiB
:硬盘大小。Sector size
:扇区大小。Disklabel type
:磁盘标签类型。Device
:分区设备名称。Boot
:是否为启动分区。Start
和End
:分区的起始和结束扇区。Sectors
:分区大小(以扇区为单位)。Size
:分区大小。Id
:分区类型ID。Type
:分区类型。
使用df
命令
df
(disk free)命令用于查看文件系统的磁盘空间使用情况,包括已用空间、可用空间等。
示例输出:
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 232G 50G 177G 23% /home /dev/sda2 72K 0 72K 0% [SWAP] /dev/sdb1 149G 30G 109G 22% /mnt/data
解释:
Filesystem
:文件系统所在的设备。Size
:文件系统的大小。Used
:已用空间。Avail
:可用空间。Use%
:已用空间百分比。Mounted on
:挂载点。
使用du
命令
du
(disk usage)命令用于查看目录或文件的磁盘使用情况,通常与-sh
选项一起使用,以人类可读的格式显示总大小。
示例输出:
$ du -sh /home 23G /home
解释:
du -sh /home
:显示/home
目录的总大小。
使用blkid
命令
blkid
命令用于查看块设备的属性,如UUID、文件系统类型等。
示例输出:
$ sudo blkid /dev/sda1: UUID="1234-5678" TYPE="ext4" /dev/sda2: UUID="9abc-def0" TYPE="swap" /dev/sdb1: UUID="5678-1234" TYPE="ext4"
解释:
UUID
:通用唯一标识符,用于标识文件系统。TYPE
:文件系统类型。
使用lsblk
和df
结合查看
有时,结合使用lsblk
和df
命令可以更全面地了解硬盘的使用情况。
示例输出:
$ lsblk -f NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 ext4 1234-5678 /home └─sda2 swap 9abc-def0 [SWAP] sdb └─sdb1 ext4 5678-1234 /mnt/data
解释:
FSTYPE
:文件系统类型。LABEL
:文件系统标签。UUID
:文件系统UUID。MOUNTPOINT
:挂载点。
使用hdparm
命令查看硬盘健康状态
hdparm
命令用于查看和设置硬盘的参数,包括硬盘的健康状态、缓存大小、传输速率等。
示例输出:
$ sudo hdparm -I /dev/sda /dev/sda: ATA device, with non-removable media Standards: Uses: ATA8-ACS revision 4 Supports ATA feature set ACS-2 Supports ATA commands Supports IDLEWIRE command Supports power management ...
解释:
hdparm -I /dev/sda
:显示/dev/sda
硬盘的详细信息,包括型号、容量、缓存大小、传输模式等。
使用smartctl
命令查看硬盘健康状态
smartctl
命令用于监控硬盘的健康状态,支持SMART(Self-Monitoring, Analysis and Reporting Technology)技术的硬盘。
示例输出:
$ sudo smartctl -a /dev/sda smartctl 7.1 2023-01-01 r5157 [x86_64-linux-5.4.0-123-generic] (local build) Copyright (C) 2002-2023 Smartmontools team Starting self-test on /dev/sda: done Reading SMART data from /dev/sda: done SMART overall-health self-assessment test result: PASSED General SMART Values: Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Enabled. Self-test execution status: ( 0) The previous self-test routine completed without error or no self-test has ever been started. Total time to complete Offline data collection: (14400) seconds. Offline data collection capabilities: (0x7b) SMART execute Offline immediate. Auto Offline data collection on/off support. Suspend Offline collection upon new command. Offline surface scan supported. Self-test supported. Conveyance Self-test supported. Selective Self-test supported. Automatic Offline data collection on/off support. Abort offline collection upon new command. Offline surface scan supported. Self-test supported. Conveyance Self-test supported. Selective Self-test supported. Automatic Offline data collection on/off support. Abort offline collection upon new command. Offline surface scan supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. No Automatic Offline data collection on/off support. Abort offline collection upon new command. No Offline surface scan supported. No Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported.
以上内容就是解答有关linux下如何查看硬盘的详细内容了,我相信这篇文章可以为您解决一些疑惑,有任何问题欢迎留言反馈,谢谢阅读。
原创文章,发布者:酷番叔,转转请注明出处:https://cloud.kd.cn/ask/10995.html