Why the result of linux commands "df" and "du" are different?
Applies to
- ONTAP 9
- NFS
- Trident
Answer
du
walks through the target and counts the space usage of each object- The target can be a directory, subdirectory, file, or the entire filesystem
df
queries the filesystem for the current space usage- The storage system enabled volume efficiency
Example:
[root@user1]# df -Ph | grep DB
192.xxx.xxx.xxx:/vol1 12T 784G 12T 7% /DB
[root@user1]# du -sh /DB/
2.7T /DB
DF
/vol/vol1/ 12884901888 847244892 12037656996 7% /vol/vol1/
/vol/vol1/.snapshot 0 0 0 0% /vol/vol1.snapshot
DF -S
Filesystem used total-saved %total-saved deduplicated %deduplicated compressed %compressed vbn zero %vbn zero
/vol/vol1/ 847244892 2560004340 75% 1515678176 44% 1044326164 31% 726488260 21%
Additional Information
Ex:
When we copy a file larger than the available space, the filesystem might initially allow the copy to proceed by using sparse file techniques or over-provisioning. However, once the actual physical space is exhausted, the copy operation fails. Despite this, the filesystem might still report the logical size of the files, which includes the sparse regions, making it seem like more data is stored than the physical capacity.
- Copy Operation: Start copying a 7GB file to a 2GB disk.
- Sparse File Handling: The filesystem writes the non-zero data blocks and skips the zero blocks, initially allowing the copy to proceed.
- Failure Point: Once the actual 2GB of physical space is exhausted, the copy operation fails.
- Disk Usage Reporting: du -sh shows the logical size of the files, including the sparse regions, which can exceed the physical capacity. df shows the actual physical space used, which remains at 2GB.
- du -sh: This command shows the actual disk usage of files and directories. It includes the space used by sparse files as if they were fully allocated, which can make it seem like more space is used than is actually available.
- df: This command shows the available and used disk space on the filesystem. It reports the actual physical space used, which might be less than what du reports if sparse files are present.