Skip to main content
NetApp Knowledge Base

Why the result of linux commands "df" and "du" are different?

Views:
716
Visibility:
Public
Votes:
0
Category:
ontap-9
Specialty:
nas
Last Updated:
3/28/2025, 6:06:36 AM

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.

  1. Copy Operation: Start copying a 7GB file to a 2GB disk.
  2. Sparse File Handling: The filesystem writes the non-zero data blocks and skips the zero blocks, initially allowing the copy to proceed.
  3. Failure Point: Once the actual 2GB of physical space is exhausted, the copy operation fails.
  4. Disk Usage Reportingdu -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.

 

NetApp provides no representations or warranties regarding the accuracy or reliability or serviceability of any information or recommendations provided in this publication or with respect to any results that may be obtained by the use of the information or observance of any recommendations provided herein. The information in this document is distributed AS IS and the use of this information or the implementation of any recommendations or techniques herein is a customer's responsibility and depends on the customer's ability to evaluate and integrate them into the customer's operational environment. This document and the information contained herein may be used solely in connection with the NetApp products discussed in this document.