Directory size displayed by du command does not match

When the directory size displayed by the du command does not match between the parent directory and child directory in Linux. How to solve the problem? The parent directory is devopsroles and the child hidden directory is “.delete”

du command does not match directory size displayed

Folder devopsroles with 12M size as below

[huupv@server01 ~]$  du -sh devopsroles
12M     devopsroles

Contain files and folders in devopsroles as below

[huupv@server01 devopsroles]$ ls -la
total 16
drwxr-xr-x  3 huupv huupv 4096 Feb 13 16:29 .
drwxr-xr-x 16 huupv huupv 4096 Feb 13 16:29 ..
drwxr-xr-x  2 huupv huupv 4096 Feb 13 16:07 .delete
-rw-r--r--  1 huupv huupv   17 Feb 13 16:29 note.txt
-rw-r--r--  1 huupv huupv    0 Feb 13 16:29 tmp.txt

In folder devopsroles different size with du -sh command.

[huupv@server01 ~]$ cd devopsroles/
[huupv@server01 devopsroles]$ pwd
/home/huupv/devopsroles
[huupv@server01 devopsroles]$ du -sh ./* | sort -hr
4.0K    ./note.txt
0       ./tmp.txt

12M=4.0K + 0? Why does not it match?

Cause: du command does not show hidden directory size.

If you do the following, the file size including the hidden directory is displayed as the command below.

[huupv@server01 devopsroles]$ du -sh .[^.]*/ ./* | sort -hr
12M     .delete/
4.0K    ./note.txt
0       ./tmp.txt

Conclusion

In this tutorial, you can solve the problem “directory size displayed by du does not match between the parent directory and child directory” in Linux. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.