Shell – du reports directory size as much bigger than the sum of its contents

disk-usageshellwildcards

Running du -shc * in the top directory gives 110G for a particular folder, whereas running the same command inside that folder gives a total size of 11G. How is that possible?

Platform Details:
OS: CentOS 6.6 x86_64
Drive type: solid-state
Volume type: RAID 6 array
RAID Controller: LSI MegaRAID SAS
Filesystem: ext3

Best Answer

Most probably you have hidden files in the folder. The point is that glob * selects only files and folders that do not start with .. So, if they do they are not passed to du command. On the other hand from top directory you get size of the directory as a whole, including dot files.

To match all files in given folder, including hidden ones try (with bash)

du -shc -- {.[!.],..?,}*

or set option dotglob so that * matches hidden files too:

shopt -s dotglob
du -shc -- *
Related Question