df 命令查看磁盘空间
Periodically, you may need to monitor or check the disk space on your system to ensure that you have enough space to install software packages or save files. There are plenty of tools on the internet for checking disk space. Linux comes with its own built-in utility called df
for checking the amount of disk space on your system. In this article, we look at how you can check disk space in Linux using the df
command.
您可能需要定期监视或检查系统上的磁盘空间,以确保您有足够的空间来安装软件包或保存文件。 互联网上有很多用于检查磁盘空间的工具。 Linux带有自己的内置实用程序df
用于检查系统上的磁盘空间量。 在本文中,我们介绍了如何使用df
命令在Linux中检查磁盘空间。
(Check disk space using Linux df command)
The df command without any options displays total blocks, used space, available disk space and mount points located on the filesystem.
不带任何选项的df命令将显示总块数,已用空间,可用磁盘空间和文件系统上的安装点。
$ df
Sample output
样品输出
(Check disk space of all filesystems)
To display disk space of all file systems, use the -a
option as shown. Apart from displaying the conventional filesystems, the -a
option displays dummy filesystems:
要显示所有文件系统的磁盘空间,请使用-a
选项,如图所示。 除了显示常规文件系统之外, -a
选项还显示虚拟文件系统:
$ df -a
Sample output
样品输出
(Check disk space in human readable format)
AS previously seen df command displays information in bytes, which is not exactly easy to read format. You can display disk space in a human-readable format using the following options.
如先前所见, df命令以字节为单位显示信息,这不是很容易读取的格式。 您可以使用以下选项以人类可读的格式显示磁盘空间。
-h
– displays disk space in GB (Gigabytes)
-h
–以GB(千兆字节)显示磁盘空间
$ df -h
Sample output
样品输出
-m
– displays disk space in MB (Megabytes)
-m
–以MB(兆字节)为单位显示磁盘空间
$ df -m
Sample output
样品输出
(Display the type of file system)
To display the file system type of your system’s mount points, use the -T
flag as shown below
要显示系统安装点的文件系统类型,请使用-T
标志,如下所示
$ df -T
Sample output
样品输出
(Check disk space of a specific directory)
To check the disk space of a specific directory, use the syntax below:
要检查特定目录的磁盘空间,请使用以下语法:
$ df -Th /directory_name
For example, to check disk space on the /var
directory , execute the command:
例如,要检查/var
目录上的磁盘空间,请执行以下命令:
$ df -Th /var
Sample output
样品输出
(Display a specific file system)
If you wish to display a specific file system, use the -t
option followed by the filesystem type.
For example, To display the ext4
filesystem , execute the command :
如果要显示特定的文件系统,请使用-t
选项,后跟文件系统类型。
例如,要显示ext4
文件系统,请执行以下命令:
$ df -t ext4
Sample output
样品输出
(Exclude a certain file system type from getting displayed)
If, say , you want to display all file systems apart from the ext4
type , use the -x
command as shown
例如,如果要显示除ext4
类型之外的所有文件系统,请使用-x
命令,如下所示
$ df -x ext4
Sample output
样品输出
(Display file system inodes)
To display information of the number of used inodes and their corresponding percentage in the filesystem, use the -i
option as shown:
要显示文件系统中已使用的inode数量及其对应百分比的信息,请使用-i
选项,如下所示:
$ df -i
Sample output
样品输出
(Getting help with df commands)
To get your way around with more command options visit the df man page as shown
要使用更多命令选项来解决问题,请访问df手册页,如图所示
$ man df
Sample output
样品输出
Additionally, to get help run the command
此外,要获取帮助,请运行命令
$ df --help
Sample output
样品输出
(Conclusion)
That was on an overviews of the various df
command options. In this guide, we walked you through how you can check disk space in Linux. Feel free to try out the commands and leave your feedback.
那是各种df
命令选项的概述。 在本指南中,我们向您介绍了如何在Linux中检查磁盘空间。 随意尝试命令并留下您的反馈。
翻译自: https://www.journaldev.com/28753/linux-df-command-check-disk-space
df 命令查看磁盘空间