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 “
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.