Linux 查看磁盘使用情况

点击访问 Linux 命令大全 >>

Linux 中可使用 df 命令查看磁盘使用情况。df 语法如下:

用法:df [选项]... [文件]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
      --direct          show statistics for a file instead of mount point
      --total           produce a grand total
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024
  -i, --inodes          显示inode 信息而非块使用量
  -k                    即--block-size=1K
  -l, --local           只显示本机的文件系统
      --no-sync         取得使用量数据前不进行同步动作(默认)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help            显示此帮助信息并退出
      --version         显示版本信息并退出

所显示的数值是来自 --block-size、DF_BLOCK_SIZE、BLOCK_SIZE
及 BLOCKSIZE 环境变量中第一个可用的 SIZE 单位。
否则,默认单位是 1024 字节(或是 512,若设定 POSIXLY_CORRECT 的话)。

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

实例1:使用 df 查看系统磁盘使用情况。如下:

[root@localhost ~]# df
文件系统                   1K-块    已用     可用 已用% 挂载点
/dev/mapper/centos-root 17811456 1261664 16549792    8% /
devtmpfs                  919480       0   919480    0% /dev
tmpfs                     931612       0   931612    0% /dev/shm
tmpfs                     931612    9740   921872    2% /run
tmpfs                     931612       0   931612    0% /sys/fs/cgroup
/dev/sda1                1038336  148576   889760   15% /boot
tmpfs                     186324       0   186324    0% /run/user/0

df 命令显示的信息非常完整,除了挂载的设备名称和挂载点外,df 还会显示当前磁盘的使用情况。如上面的 /dev/sda1,总大小为 1038336 ,已使用 148576,剩余 889760。明显这种方式不利于查看,还需要自己将字节换算成MB、GB,非常麻烦。

实例2:使用 -h 选项以可读性好的方式显示。如下:

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   17G  1.3G   16G    8% /
devtmpfs                 898M     0  898M    0% /dev
tmpfs                    910M     0  910M    0% /dev/shm
tmpfs                    910M  9.6M  901M    2% /run
tmpfs                    910M     0  910M    0% /sys/fs/cgroup
/dev/sda1               1014M  146M  869M   15% /boot
tmpfs                    182M     0  182M    0% /run/user/0

上面 /dev/sda1 总大小为 1014M,已使用 146M,未使用 869M。

实例3:使用 -T 选项输出文件系统类型,如下:

[root@localhost ~]# df -hT
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs        17G  1.3G   16G    8% /
devtmpfs                devtmpfs  898M     0  898M    0% /dev
tmpfs                   tmpfs     910M     0  910M    0% /dev/shm
tmpfs                   tmpfs     910M  9.6M  901M    2% /run
tmpfs                   tmpfs     910M     0  910M    0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  146M  869M   15% /boot
tmpfs                   tmpfs     182M     0  182M    0% /run/user/0

实例4:使用 -t 筛选出指定文件系统类型的磁盘信息,这样可以去除很多“无用”的信息,如:tmpfs。如下:

[root@localhost ~]# df -hTt xfs
文件系统                类型  容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs    17G  1.3G   16G    8% /
/dev/sda1               xfs  1014M  146M  869M   15% /boot

上面的命令告诉 df 命令只须显示已经挂载的 ext3 文件系统的信息。

说说我的看法
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号