因为df和du的统计机制不一样。 du会把指定目录下所有文件、目录、目录下的文件都统计。是建立在文件系统能看到的的确确是有这样一些文件的基础上的。也就是说我们能在文件系统里面看到的文件才会被du统计。
df(df命令通过查看文件系统磁盘块分配图得出总块数与剩余块数。): 这要从程序写文件的方式来谈起,一个进程要向一个文件里面写东西,那么会得到一个pointer, 然后向指针指向的文件(磁盘区域)写入。假如由于某些原因(也可能人为)被指向的文件被删除了,但是(
原文:Whenyou open a file, you get apointer.
is there or not.
at a predeterminedlocation.
blocks are used by the write operation.
下面是整个原文: This article explains how reporting disk usage du and reportingfree disk space
on file systems df may show different numbers.
du
--
The du user command gives the number of kilobytes contained in allfiles and,
recursively, directories within each specified directory or file(filename).
If filename is missing, `.' (the current directory) isused.
has multiple links to it is only counted once.
EXAMPLE:
Note that the last number, 1211 is the grand total (in kilobytes)for the
directory.
df
--
The df user command displays the followinginformation:
Used without arguments, df reports on all mounted filesystems.
EXAMPLE:
Note: used plus avail is less than the amount of space in the filesystem
(kilobytes) because the system reserves a fraction of the space inthe file
system to allow its allocation routines to workwell.
typically about 10%.
the man pages on tunefs(
system, except for this reserve, is in use, only the super-user canallocate
new files and data blocks to existingfiles.
system to be overallocated.
df may report that the file system is more than 100%utilized.
If arguments to df are disk partitions (for example, /dev/ip0as orpath names),
df produces a report on the file system containing the namedfile.
shows the amount of space on the file system containing the currentdirectory.
Problem Definition
------- ----------
This section gives the technical explanation of why du and dfsometimes report
different totals of disk space usage.
When a program that is running in the background writes to a filewhile the
process is running, the file to which this process is writing isdeleted.
Running df and du shows a discrepancy in the amount of disk spaceusage.
df command shows a higher value.
Explanation Summary
----------- -------
When you open a file, you get apointer.
references this filepointer.
is there or not.
at a predeterminedlocation.
blocks are used by the write operation.
The df command reports the number of disk blocks used while du goesthrough the
file structure and and reports the number of blocks used by eachdirectory.
far as du is concerned, the file used by the process does notexist, so it does
not report blocks used by this phantomfile.
used, and it reports the blocks used by this phantomfile.