linux下如何查看硬盘

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:是否为启动分区。
  • StartEnd:分区的起始和结束扇区。
  • 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:文件系统类型。

使用lsblkdf结合查看

有时,结合使用lsblkdf命令可以更全面地了解硬盘的使用情况。

示例输出:

$ 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

(0)
酷番叔酷番叔
上一篇 2025年8月15日 07:49
下一篇 2025年8月15日 07:54

相关推荐

  • 如何比较变量MD5值是否相同?

    核心方法:字符串直接对比MD5值本质是32位十六进制字符串(如d41d8cd98f00b204e9800998ecf8427e),只需直接比较字符串内容:md5_2=”d41d8cd98f00b204e9800998ecf8427e”if [ “$md5_1” = “$md5_2” ]; then echo……

    2025年7月17日
    5100
  • Linux如何创建子目录管理文件?

    核心命令:mkdirmkdir(make directory)是Linux创建目录的标准命令,其基本语法为:mkdir [选项] 目录名基础操作示例创建单个子目录在当前位置创建名为 docs 的子目录:mkdir docs在指定路径创建子目录在 /home/user/projects 下创建 backup 子目……

    2025年8月8日
    4200
  • linux如何查看spi信息

    Linux 中,可以使用 dmesg | grep spi 命令查看 SPI 信息,

    2025年8月14日
    3600
  • Linux如何查看文件夹的所有者?

    在Linux系统中,文件夹所有者(即文件所有者)是文件权限管理的核心概念,决定了用户对文件夹的读取、写入和执行权限,查看文件夹所有者有助于排查权限问题、管理文件系统安全以及进行系统审计,本文将详细介绍Linux中查看文件夹所有者的多种方法,包括基础命令、高级选项及实际应用场景,基础查看命令:ls命令ls是Lin……

    2025年9月9日
    2800
  • 进程调度在操作系统中起什么作用?

    在Linux操作系统中,进程调度是核心功能之一,它决定了CPU资源如何分配给多个同时运行的进程,作为多任务系统的基石,调度器需要平衡响应速度、吞吐量和公平性,直接影响系统性能和用户体验,以下是Linux进程调度的详细解析:CPU核心数量有限(如4核、8核),但系统通常同时运行数百个进程(如浏览器、后台服务),调……

    2025年7月7日
    4900

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

400-880-8834

在线咨询: QQ交谈

邮件:HI@E.KD.CN

关注微信