在使用Linux时,可能会出现这样一种情况:您想知道Linux系统上某个特定文件系统消耗的空间量,或者某个特定文件系统上有多少可用空间。LINUX对命令友好,为此提供了一个命令行实用程序 即 df 命令,显示包含每个文件名参数的文件系统上可用的磁盘空间量。
- 如果没有文件名通过df命令作为参数传递,那么它将显示当前所有文件上的可用空间 安装 文件系统
- .这是你可能想知道的原因 df 在文件系统上执行此命令需要很深的空间,因此无法在文件系统上执行此命令。
- 默认情况下, df 显示中的磁盘空间 1K 阻碍。
- df以第一个可用大小的单位显示值 –块大小 (这是一个选项)和DF_BLOCK_SIZE、BLOCKSIZE和BLOCK_SIZE环境变量。
- 默认情况下,单位设置为1024字节或512字节(如果设置了POSIXLY_CORRECT)。在这里,大小是一个整数,可选的单位是 K、 M,G,T,P,E,Z,Y (单位为千克)。
df语法:
df [OPTION]...[FILE]...OPTION : to the options compatible with df command FILE : specific filename in case you want to know the disk space usage of a particular file system only.
使用df命令
假设您有一个名为kt的文件。txt,您想知道包含此文件的文件系统上使用的磁盘空间,然后可以使用 df 在这种情况下:
// using df for a specific file //$df kt.txtFilesystem 1K-blocks Used Available Use% Mounted on /dev/the2 1957124 1512 1955612 1% /snap/core /* the df only showed the disk usage details of the file system thatcontains file kt.txt */
现在,如果您不提供任何文件名t df,在这种情况下,df会显示所有已安装文件系统的磁盘使用信息,如下所示:
//using df without any filename //$dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/loop0 18761008 15246876 2554440 86% /none 4 0 4 0% /sys/fs/cgroupudev 493812 4 493808 1% /devtmpfs 100672 1364 99308 2% /runnone 5120 0 5120 0% /run/locknone 503352 1764 501588 1% /run/shmnone 102400 20 102380 1% /run/user/dev/the2 1957124 1512 1955612 1% /snap/core /* in this case df displayed the disk usage details of allmounted file systems */
df命令的选项
- -a、 ——全部: 它还包括输出中的所有虚拟文件,这些文件实际上具有零块大小。
- -B、 -块大小=S: 这是我们在上一段中讨论的选项,用于按大小缩放大小,如 -BM 以1048576字节为单位打印大小。
- –总计: 它用于显示大小的总计。
- -h、 ——可读性: 它以人类可读的格式打印尺寸。
- -H、 ——si: 此选项与-h相同,但它使用1000次幂而不是1024次幂。
- -i、 ——索引节点: 当您希望显示inode信息而不是块使用情况时,可以使用此选项。
- -k: 它的用途类似于-block-size-1k。
- -l、 ——本地: 这将仅显示本地文件系统的磁盘使用情况。
- -P、 -便携性: 它使用POSIX输出格式。
- -t、 -类型=类型: 它将只显示具有类型的文件系统的输出。
- -T、 ——打印类型: 此选项用于打印输出中显示的文件系统类型。
- -x、 -排除类型=类型: 它将从输出中排除所有具有类型的文件系统。
- -五: 忽略,出于兼容性原因包含。
- –不同步: 这是默认设置 即 在获取使用信息之前不要调用同步。
- –同步: 它在获取使用信息之前调用同步。
- ––帮助: 它会显示一条帮助消息并退出。
- -版本: 它显示版本信息并退出。
将df与选项一起使用的示例
1.使用-a: 如果需要显示所有文件系统以及块大小为零的文件系统,则使用 -a 带有df的选项。
//using df with -a//$df -aFilesystem 1K-blocks Used Available Use% Mounted on/dev/loop0 18761008 15246876 2554440 86% /none 4 0 4 0% /sys/fs/cgroupudev 493812 4 493808 1% /devtmpfs 100672 1364 99308 2% /runnone 5120 0 5120 0% /run/locknone 503352 1764 501588 1% /run/shmnone 102400 20 102380 1% /run/user/dev/sda3 174766076 164417964 10348112 95% /hostsystemd 0 0 0 - /sys/fs/cgroup/* in this casesystemd file system having zero block size is also displayed */
2.使用-h: 这用于使df命令以人类可读的格式显示输出。
//using -h with df//$df -h kt.txtFilesystem 1K-blocks Used Available Use% Mounted on /dev/the2 1.9G 1.5M 1.9G 1% /snap/core /*this output is easily understandable by the user and allcause of -h option */
在上面的例子中,G和M分别代表千兆字节和兆字节。您可以将-h与df一起使用,只为所有装载的文件系统生成可读格式的输出,而不仅仅是包含kt的文件系统的输出。txt文件。
3.使用-k: 这将以1K块显示文件系统信息和使用情况。
//using -k with df//$df -k kt.txtFilesystem 1K-blocks Used Available Use% Mounted on /dev/the2 1957124 1512 1955612 1% /snap/core /* no change cause theoutput was initiallyshown in the usageof 1K bytes only */
4.使用–总计: 此选项用于生成输出中某个大小、已用和可用列的总计。
//using --total with df//$df --total Filesystem 1K-blocks Used Available Use% Mounted on/dev/loop0 18761008 15246876 2554440 86% /none 4 0 4 0% /sys/fs/cgroupudev 493812 4 493808 1% /devtmpfs 100672 1364 99308 2% /runnone 5120 0 5120 0% /run/locknone 503352 1764 501588 1% /run/shmnone 102400 20 102380 1% /run/user/dev/the2 1957124 1512 1955612 1% /snap/core total 21923492 15251540 5712260 92% - /* the total row is added in the output */
5.使用-T: 在该选项的帮助下,您将能够看到相应类型的文件系统,如图所示。
/using -T with df//$df -T kt.txtFilesystem Type 1K-blocks Used Available Use% Mounted on /dev/the2 squashfs 1957124 1512 1955612 1% /snap/core /* you can use-T with df onlyto display type ofall the mountedfile systems */
6.使用-t: 当您希望仅使用特定类型的文件系统的磁盘使用信息时,可以使用此选项。
//using -t with df//$df -t squashfsFilesystem 1K-blocks Used Available Use% Mounted on/dev/loop0 18761008 15246876 2554440 86% //dev/the2 1957124 1512 1955612 1% /snap/core /*so the df displayed only the info of the filesystems having typesquashfs */
7.使用-x: 现在,您还可以告诉df显示所有文件系统的磁盘使用信息,除了那些具有特定类型的文件系统 -x 选项
//using -x with df//$df -x squashfsFilesystem 1K-blocks Used Available Use% Mounted onnone 4 0 4 0% /sys/fs/cgroupudev 493812 4 493808 1% /devtmpfs 100672 1364 99308 2% /runnone 5120 0 5120 0% /run/locknone 503352 1764 501588 1% /run/shmnone 102400 20 102380 1% /run/user/* in this case info of/dev/the2 and /dev/loop0file systems aren'tdisplayed cause they are of type squashfs */
8.使用-i: 此选项用于显示 伊诺德 输出中的信息。
//using -i with df//$df -i kt.txtFilesystem Inodes IUsed IFree Iuse% Mounted on /dev/the2 489281 48 489233 1% /snap/core/*showing inode infoof file systemhaving file kt.txt */
当使用-i选项时,第二列、第三列和第四列将显示与索引节点相关的图形,而不是与磁盘相关的图形。
9.使用–-sync: 默认情况下,df命令生成带有 –不同步 选项,在报告使用信息之前不会执行同步系统调用。现在我们可以使用–-sync选项强制同步,从而使输出完全更新。
//using --sync option//$df --syncFilesystem 1K-blocks Used Available Use% Mounted on/dev/loop0 18761008 15246876 2554440 86% /none 4 0 4 0% /sys/fs/cgroupudev 493812 4 493808 1% /devtmpfs 100672 1364 99308 2% /runnone 5120 0 5120 0% /run/locknone 503352 1764 501588 1% /run/shmnone 102400 20 102380 1% /run/user/dev/the2 1957124 1512 1955612 1% /snap/core /* in this case no change in the outputis observed cause it is possible that there is noupdate info present tobe reflected */
10.使用-l: 当我们运行df命令时,默认情况下,它会显示任何外部安装的文件系统,包括来自外部NFS或Samba服务器的文件系统。我们可以使用-l选项语法隐藏这些外部文件系统的信息,其语法如下所示。
$df -l
所以,这都是关于df命令的。