Today I will introduce to you the usage of two commands in the Linux system-df and du. The df command can view the disk usage information of the file system, and du can be used to view the size of the file or directory.
df
Usage: df [options]
Common options:
-a Show all File system
-h Display in an easy-to-read manner
-i Disk capacity is not displayed, only the number of inodes used
-T Display file system
Let’s do a demonstration
1. Without any parameters
# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 3986648 0 3986648 0% /dev tmpfs 3999984 0 3999984 0% /dev/shm tmpfs 3999984 528 3999456 1% /run tmpfs 3999984 0 3999984 0% /sys/fs/cgroup /dev/vda1 41931756 19293976 22637780 47% / /dev/vdb1 52403200 476572 51926628 1% /data /dev/vdb2 104806400 27960008 76846392 27% /www tmpfs 799996 0 799996 0% /run/user/0
2 .Add the -h option
to get the disk usage of each mount point, but it is not very easy to read. Let's add the -h option to see the effect
# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 528K 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vda1 40G 19G 22G 47% / /dev/vdb1 50G 466M 50G 1% /data /dev/vdb2 100G 27G 74G 27% /www tmpfs 782M 0 782M 0% /run/user/0
3. Add the -T option
We also want to know what kind of file system the mount point uses, so we need to add Use the -T option
# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 528K 3.9G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vda1 xfs 40G 19G 22G 47% / /dev/vdb1 xfs 50G 466M 50G 1% /data /dev/vdb2 xfs 100G 27G 74G 27% /www tmpfs tmpfs 782M 0 782M 0% /run/user/0
4. Add the -i option
If we want to see the inode usage, then we need to use the -i option
# df -ih Filesystem Inodes IUsed IFree IUse% Mounted on devtmpfs 974K 359 973K 1% /dev tmpfs 977K 1 977K 1% /dev/shm tmpfs 977K 562 977K 1% /run tmpfs 977K 17 977K 1% /sys/fs/cgroup /dev/vda1 20M 188K 20M 1% / /dev/vdb1 25M 4 25M 1% /data /dev/vdb2 50M 494K 50M 1% /www tmpfs 977K 5 977K 1% /run/user/0
Except In addition to the above options, df also has a very useful little function, which can check which file system a file belongs to.
# df /etc/my.cnf Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 41931756 19294292 22637464 47% /
du
Like df, du is also a frequently used command. Sometimes, the server disk is almost full and we need to clean up unnecessary large files. At this time, we need the du command.
Usage: du [option] file or directory name
Commonly used options are as follows:
-a Display the size of all files
-h Display in human-readable form.
-s Display only the total
-S Display the directory size, but does not include the size of the subdirectory
# 显示文件大小 # du -h wp-fastest-cache.0.9.0.7.zip 456K wp-fastest-cache.0.9.0.7.zip # 显示目录大小,默认会显示该目录下所有文件,如只想显示目录大小,需要加上-s选项 # du -sh /root 114M /root # 显示目录下文件大小总和,不包括子目录 # du -sSh /root 84M /root
Below, a very common scenario is given: the system disk is almost full and needs to be cleaned up.
First, we use the df command to check which file system is almost running out of space. After locating the mount point, use the du command to go through the directories one by one to check the directory size and locate the directory that takes up the largest space. Then look at the files that can be deleted in this directory and delete these files.
The above is the detailed content of How to check disk and directory status information under Linux. For more information, please follow other related articles on the PHP Chinese website!