df and du giving different results

2.9k views Asked by At

When I use df -h it gives following result for /appl directory

/appl                   39G    32G   6.7G    83%    /appl

But when I enter that directory cd /appl and run du -sh it is giving me the following result :

 4.9G   .

If the /appl mountpoint is occupied 32GB why is it showing that it's directories total to 4.9G?

2

There are 2 answers

6
Santosh A On

Firstly df and du are two completely different linux utilities.

df = Disk free
du = Disk usage

df (More info on df) will read the meta data of the disk partition containing the specified folder which in your case is app1 and return the disk partition information rather than that of the actual directory.

But du(More info on du) will runs through the directory tree specified and counts the sum size of all the files under the directory and return the total space occupied by that directory.

Next to answer your question:
cd /appl or cd <mount_point> is not possible.
To check where is the partition app1 mounted use mount command.

The confusion you see is because there must be a folder called app1 under / directory and also a partition named app1.

Once you locate the mount point of the app1 partition, cd to that directory and then run du -sh the expected output should be 32G after taking some time.

Note : app1 partition mount point and /app1 are not same.

0
DreamOneX On

At first, you should know the different between du and df. Wikipedia says

du is to display the file space allocated to each file

df display the amount of available disk space for file systems on which the invoking user has appropriate read access

So, there are several possible reasons for this to happen

A few examples

  1. Some application still open deleted file, check through lsof +aL1
  2. Files larger than their true size. This will fool du, but not df
  3. if there are files at the mount point before something mounts to the mount point, those files will be hidden to du, check through debugfs