Contents

LinuxSys:linux查看文件系统硬盘使用情况

本文采用知识共享署名 4.0 国际许可协议进行许可,转载时请注明原文链接,图片在使用时请保留全部内容,可适当缩放并在引用处附上图片所在的文章链接。

linux查看文件系统硬盘使用情况

df 命令

df 命令,用于显示 Linux 系统中各文件系统的硬盘使用情况,包括文件系统所在硬盘分区的总容量、已使用的容量、剩余容量等。

前面讲过,与整个文件系统有关的数据,都保存在 Super block(超级块)中,而 df 命令主要读取的数据几乎都针对的是整个文件系统,所以 df 命令主要是从各文件系统的 Super block 中读取数据。

df 命令的基本格式为:

[root@localhost ~]# df [选项] [目录或文件名]

表 1 列出了 df 命令几个常用的选项,以及它们各自的作用。

选项 作用
-a 显示所有文件系统信息,包括系统特有的 /proc、/sysfs 等文件系统;
-m 以 MB 为单位显示容量;
-k 以 KB 为单位显示容量,默认以 KB 为单位;
-h 使用人们习惯的 KB、MB 或 GB 等单位自行显示容量;
-T 显示该分区的文件系统名称;
-i 不用硬盘容量显示,而是以含有 inode 的数量来显示。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
zyh@zyh ~ $ df -h
文件系统        容量  已用  可用 已用% 挂载点
udev            3.8G     0  3.8G    0% /dev
tmpfs           767M  3.6M  764M    1% /run
/dev/nvme0n1p2  117G   57G   55G   51% /
tmpfs           3.8G  197M  3.6G    6% /dev/shm
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           3.8G     0  3.8G    0% /sys/fs/cgroup
/dev/nvme0n1p1  511M  6.1M  505M    2% /boot/efi
/dev/sda2       932G  843G   89G   91% /mnt/DG
tmpfs           767M   12K  767M    1% /run/user/121
tmpfs           767M   44K  767M    1% /run/user/1000

udev / tmpfs

tmpfs - essentially is a virtual filesystem located in RAM instead of a disk device. Since it’s a filesystem, data saved there has a certain order, just like a regular filesystem for a disk storage would have, however the files reside in memory and are not persistent (that is, those files will be gone next time you power off the computer - and it’s OK, that information is necessary only for the duration of the system running and no reason to store data on disk). In some other Linux distributions you might see /tmp directory serve as a mountpoint for one such tmpfs filesystem.

udev is also a filesystem, which is also virtual, however there’s many more pieces to the overall udev system. Information stored in this filesystem is of course related to the devices files - aka the interface between actual physical device and the user. You can read more about it on a related question. Interesting behavior of this filesystem is that data doesn’t really accumulate in certain files when you write to them - this is different compared to regular disk filesystems. For instance, consider the character device /dev/null or /dev/tty1.

As for “What should I do with them?” question, the answer is “nothing”. For a casual user they’re not interesting. They run from RAM, they don’t eat up actual disk space, and they play somewhat important purpose in the system. Software developers, sysadmins, and advanced users - they’ll have a good reason to create another tmpfs for their purpose or they’ll have a reason to poke around /dev or modify the configuration/rules for how udev treats newly added devices to the system. But of course - those types of users do have a reason to “do something” about these filesystems

Note that although /dev/sda1 appears in Filesystem column, it is actually a device file. What actually is on that device represented by /dev/sda1 might be ext4 or NTFS filesystem, and you can see that with lsblk -f or df -T command.

参考

Linux df用法详解:查看文件系统硬盘使用情况

[What is “udev” and “tmpfs”](https://askubuntu.com/questions/1150434/what-is-udev-and-tmpfs)