DU vs DF – Why du and df show different results in Linux

df vs du

DU vs DF – Why du and df show different results in Linux?

This is a common problem and question of every sysadmin that why they got different results in du and df. Mostly sysadmin relies on du over df for accurate results. In this article, we learn some basic facts about df and du to help you choose which one better and where to use.

Basic Definition:

df(Disk Free):

df reads disk blocks directly in the filesystem metadata and its trust on the superblock information . df reads the deleted file information also which is open in the running process. This always happens in case of big directory deletion which is used by large audiences. This command reads how much disk is totally free and trust filesystem metadata. This is the reason it gives you faster results.

df -h

du(Disk Usage): 

du reads every file in the directory and read their size. If any file deleted and open in the running process, it will not take any reference of the deleted file. du relies on which file currently in the directory and what is actual size. This is the reason it is slower than the df.

du -h

Conclusion: 

We can say df work on the filesystem and on the other hand du work on files. 

When to use df or du?

DF-

1- Use df in the new system both will show the same results because there is no delay or more running processes.
2- For daily operations use df because it is much faster and we required an overview of space
3- scripts where you create small or fewer files for a faster solution.

DU –

1- When you are running very low space in the directory use du to get all files accurate size.
2- Scripts where you create files on a large scale.
3- Disk size troubleshooting the best option is du.
At this point, you have understood the basic difference between du and df.

Leave a Comment

Your email address will not be published. Required fields are marked *