Directory size displayed by du command does not match

When the directory size displayed by 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 child hidden directory is “.delete”

Folder devopsroles with 12M size as below

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

The contain files and folder 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 command below.

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

Conclusiond

In this tutorial, you can solve problem “directory size displayed by du does not match between the parent directory and child directory” in linux.

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. 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 *

Comment moderation is enabled. Your comment may take some time to appear.

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