Du and DF
[[email protected] samba]# dumpe2fs/dev/sda3|grep "Block size" 4096 bytes
The actual size of the du content, in bytes, added to the statistical file size
DF occupies space size, in blocks, statistics block usage
The du-s command increments the total number of blocks used by the file system by adding the number of blocks used by all directories, symbolic links, and files in the specified file system, while the DF command obtains the total number of blocks and remaining blocks by viewing the file system disk block allocation graph. File system allocation Some of the disk blocks used to record some of its own data, such as I node, disk distribution map, indirect blocks, super blocks and so on. This data is not visible to most user-level programs, often referred to as meta data.
The du command is a user-level program that does not take meta data into account, while the DF command looks at the file system's disk allocation diagram and considers meta data. The DF command obtains real file system data, while the DU command only looks at parts of the file system.
So we don't need to look at the match between Du and the value returned by DF, but just understand that the value returned by the Du-s command reflects the number of disk blocks allocated to the file and directory, while the DF command reflects the actual allocation of the file system. The DF command reflects the fact that the user data (files and directories) and meta data are included.
Common DF and du inconsistencies are issues with file deletion. When a file is deleted, it is not visible in the file system directory, so du will not count it anymore. However, if there is a running process that holds the handle to the deleted file, the file will not actually be deleted on the disk and the information in the partition's Super block will not change. This way DF will still count the deleted files.
If a process opens a large file, the large file is dropped directly by RM or MV, then du updates the statistics, DF does not update the statistics, or the space is not released. Until the process of opening the large file was killed.
As a result, if you delete the file below/var/spool/clientmqueue periodically, the space is not released until you kill the process.
Df-h/dev/sda1
DD If=/dev/zero Of=myfile.iso bs=1024k count=1000
Compare the results of DU with DF
Df-h/dev/sda1 separately view mount to/var directory
du-sh/var/view at this time the results are basically the same
Simulate a process to open this large file and then delete this large file
Tail-f Myfile.iso &
Rm-f Myfile.iso
At this point, compare the results of DU and DF
First confirm that there is a process holding the myfile.iso handle.
lsof | grep myfile.iso;du-sh/var/;d f-h/dev/sda1
As you can see, the DF results are unchanged, and Du is no longer counting the deleted file Myfile.iso.
Stop the simulation process and compare the Du and DF results
lsof | grep myfile.iso;du-sh/var/;d f-h/dev/sda1
Where to pay attention at work
(1) When there is a large difference between Du and DF, consider whether a deleted file is not completed, by lsof the command, and then stop the related process.
(2) You can use the empty file to replace the deletion of files, the way is: Echo > Myfile.iso.
(3) For the log files that frequently occur delete problems, in the order of renaming, emptying, deleting the sequence of operations.
(4) In addition to RM, some commands will be indirectly deleted files, such as the gzip command after the completion of the deletion of the original file, in order to avoid the deletion of the problem, before compressing to confirm that no process to open the file.
How du works
The du command treats the statistic file by calling Fstat This system call, getting the file size. Its data is based on file acquisition, so there is a lot of flexibility, not necessarily for a partition, can span multiple partitions operation. If there are many files in the target directory, the Du speed will be slow.
How DF Works
The DF command uses the STATFS system call, which directly reads the partition's Super block information to get the partition usage. Its data is based on partition metadata, so it is only for the entire partition. Because DF reads the super block directly, the speed is not affected by the number of files.
Du-Report disk space usage
-A,--all
Displays statistics on all files, not just subdirectories.
-B,--bytes
Outputs the size in bytes, overriding the default 1024-byte count unit.
--block-size=size
The output is in block size, and the size of the block is sized bytes. (new option for file-utils-4.0)
-C,--total
The total of all these parameters is given after all parameters have been processed. This option is used to give the sum of the space used by a specified set of files or directories.
-D,--dereference-args
A symbolic connection that references a command-line argument. It does not affect other symbolic connections. This is useful for finding the disk usage of directories such as/usr/tmp,/usr/tmp, and so on, which are usually symbolic connections. Translation: For example, create a directory test under/var/tmp, and/usr/tmp is a symbolic connection that points to/var/tmp. Du/usr/tmp returns an/usr/tmp, and du-d/usr/tmp returns two/usr/tmp,/usr/tmp/test.
--exclude=pattern
In recursion, ignores files or subdirectories that match the specified pattern. The pattern can be any Bourne Shell's file glob mode. (new option for file-utils-4.0)
-H,--human-readable
Append a letter representing the size unit for each number, as in M for binary megabytes.
-H,--si
The same effect as the-h parameter, only uses the legal SI unit (with a power of 1000 instead of a power of 1024, so that M represents 1000000 instead of 1048576). (new option for fileutils-4.0)
-K,--kilobytes
The output is the size of the count unit in 1024 bytes.
-L,--count-links
Count the size of all files, including those that have been counted (as a hard connection).
-L,--dereference
Reference the symbolic connection (not the connection point itself, but the disk space used by the file or directory to which the connection points).
-M,--megabytes
The output in megabytes is the size of the count unit (that is, 1,048,576 bytes).
--max-depth=n
Outputs only the totals of the command line parameters that are less than or equal to the nth level of the directory. The--max-depth=0 function is the same as the-s option. (new option for fileutils-4.0)
-S,--summarize
Only the sum is displayed for each parameter.
-S,--separate-dirs
The size of each directory is reported separately, excluding the size of subdirectories.
-X,--one-file-system
Ignores directories that are not in the same file system as the parameters being processed.
-X file,--exclude-from=file
The same as--exclude except to get the schema from the specified file. Patterns are listed as rows. If the specified file is '-', then read the pattern from the standard input. (new option for fileutils-4.0) GNU Standard Options
--help
Exit normally after outputting the help information on the standard output.
--version
Exits normally after output version information on the standard output.
[email protected] ~]# du
Show only directories by default
[Email protected] ~]# du-a
Displays all file and directory sizes in the current directory
[email protected] ~]# du ipband-0.8.1-1.i386.rpm
Displays the space occupied by the specified file
DF-Report The use of file system disk space
-A,--all
List file systems that include block 0
--block-size=size Use Size-byte blocks
Specify the size of the block
-H,--huma-readable
Display size in a common format (e.g. 1K 234M 2G)
-H,--si
Ditto, but the 1k here equals 1000 bytes instead of 1024 bytes.
-I.,--inodes
Use information index points instead of blocks to represent usage status
-K,--kilobytes
Specifies that the block size equals 1024 bytes to display the usage status
-L,--local
Show local file system usage only
-M,--megabytes
Displays usage by specifying a block size equal to 1048576 bytes (1M)
--no-sync
Disable call synchronization (default) before obtaining usage information
-P,--portability
Output using POSIX format
--sync
Call synchronization before getting the usage information
-T,--type=type
Displays only file systems of the specified type (types)
-T,--print-type
Output the type of each file system
-X,--exclude-type=type
Only file systems other than the specified type (type) are displayed.
-V (Ignore)
--help
Export the command's Help information and exit
--version
Output version information and exit
Df-ia #列出各文件系统的i节点使用情况
Df-t #列出文件系统的类型