Home > Article > Operation and Maintenance > How to check Linux hard disk space usage
-df
(Full name: disk free)df
Command to view the disk space usage in the file system in units of disk partitions
-h或--human-readable #使用人类可读的格式,这也是比较常见的查看方式 -i或--inode #查看分区inode使用情况
df
Command [whb@VM_0_12_centos test]$ df
Filesystem
: Partition
1K-blocks
: Total number of blocks
Used
: Number of blocks used
##Available: Number of blocks available
Use%: Usage rate
Mounted on: Mounted directory
Used Available is not necessarily equal to 1K-blocks, because the system will reserve part of the space for other uses
option
df command is actually not conducive to us directly checking the space usage in the partition, so we more commonly use
df -h to check,
-h option means
-human-readable: Use human-readable format, which is also a common viewing method
[whb@VM_0_12_centos test]$ df -h Filesystem Size Used Avail Use% Mounted on # 再次强调:Size 不一定 = Used + Avail1.5
option
inode. This is also a problem you may encounter when using
Linux, so how to check it? Using
-i option
[whb@VM_0_12_centos test]$ df
Inodes: Total inodes
IUsed: Number of used inodes
IFree: Total number of remaining inodes
inodeUnreasonable allocation will result in unused space, but there is no
inode number, so this parameter needs to be paid attention to! Don’t wait until then, the person is dead and the money is not spent~~
(Full name: disk usage)
du command also checks the hard disk usage, but there are certain differences between the two.
du The command is to count the hard disk space usage of files or directories and their subdirectories. Generally, it can help us quickly locate whether there are oversized files or other special files in the directory. size files.
#df The command is to count the overall usage of the disk partition.
#du The command will directly search for all file data in a specific directory and accumulate statistics, so it will take a little time to execute the command.
df command extracts information directly from the file system, so it is faster.
du
-a或--all #列出所有的文件和目录容量大小而不仅仅列出目录容量大小 -s或--summarize #仅显示总计,只列出最后加总的值 -h或--human-readable #以K,M,G为单位,提高信息的可读性 -c或--total #除了列出文件和目录的容量大小外,最后在列出总容量 --max-depth=N #递归显示(仅仅是显示)时的递归深度小于等于N。--max-depth=0相当于-s参数
Directory capacity = the size of the directory itself, the total size of all files in the directory (including subdirectories and ordinary files)
#方便测试,给大家建立了如下目录结构 [whb@VM_0_12_centos test]$ tree . . |-- dir1 | |-- dir2 | | `-- file2.txt | `-- file1.txt |-- dirx | `-- filex.txt `-- file.txt [whb@VM_0_12_centos test]$ du #默认统计各个目录+目录下文件大小(目录容量),但只以目录形式显示 480 ./dirx 400 ./dir1/dir2 660 ./dir1 1148 .2.5
[whb@VM_0_12_centos test]$ du -a #列出所有的文件大小和目录容量而不仅仅列出目录容量,默认只统计目录容量 4 ./file.txt 476 ./dirx/filex.txt 480 ./dirx #这里为何是480?回看一下我们定义的概念,你就明白了 396 ./dir1/dir2/file2.txt 400 ./dir1/dir2 256 ./dir1/file1.txt 660 ./dir1 1148 .
[whb@VM_0_12_centos test]$ du -s #仅显示总计,只列出最后加总的值。 1148 .
[whb@VM_0_12_centos test]$ du -h #以K,M,G为单位,提高信息的可读性 480K ./dirx 400K ./dir1/dir2 660K ./dir1 1.2M . [whb@VM_0_12_centos test]$ du -ah #选项可以组合 4.0K ./file.txt 476K ./dirx/filex.txt 480K ./dirx 396K ./dir1/dir2/file2.txt 400K ./dir1/dir2 256K ./dir1/file1.txt 660K ./dir1 1.2M . [whb@VM_0_12_centos test]$ du -h file.txt #也可以直接显示文件大小
[whb@VM_0_12_centos test]$ du -c #除了列出文件和目录的容量大小外,最后在列出总容量 480 ./dirx 400 ./dir1/dir2 660 ./dir1 1148 . 1148 total [whb@VM_0_12_centos test]$ du -ch 480K ./dirx 400K ./dir1/dir2 660K ./dir1 1.2M .
[whb@VM_0_12_centos test]$ du --max-depth=0 -h 1.2M . #递归显示(仅仅是显示)时的递归深度小于等于N。--max-depth=0相当于-s参数 [whb@VM_0_12_centos test]$ du --max-depth=1 -h 480K ./dirx 660K ./dir1 1.2M . [whb@VM_0_12_centos test]$ du --max-depth=2 -h 480K ./dirx 400K ./dir1/dir2 660K ./dir1 1.2M .
The above is the detailed content of How to check Linux hard disk space usage. For more information, please follow other related articles on the PHP Chinese website!