I have a normal folder and so when I right click, go to properties and check its data size, it gives 37.3KB. But when I use the du command, it shows 104KB
Shouldn't these two give the same answer?
The answer by @Steve Summit along with the followup comments overlook some useful information for understanding the problem:
ls -ls
will not show hidden subdirectories.ls -las
.-R
option.find . -ls
, which does show subdirectories.du
shows blocks, which hold "many" bytesls
) says that the result of -s
differed across implementations (some may show 1024 for instance):
Earlier versions of this standard did not have the -k option, which meant that the -s option could not be used portably as its block size was implementation-defined, and the units used to specify the number of blocks occupied by files in a directory in an ls -l listing were fixed as 512-byte units.
du
says it should be 512-byte units, just like ls -l
.To account for the missing space:
By the way, the -ls
option of find
is mentioned in the standard only in the rationale. But it works with Linux.
It is important to note that hardlinks matter when computing the size of a directory. Two hardlinks to the same file don't take more disk space and share inode number (by definition) but a simple count of file sizes will count them in double.
There's this switch to at least GNU du:
-l, --count-links
count sizes many times if hard linked
The du command recursively descends all directories and subdirectories and always gives you the total contained anywhere beneath.
The properties tab in a GUI doesn't always do this. Sometimes there's a checkbox (there, or in some other preferences dialog) controlling whether folder sizes are computed recursively, or only give you the top level. Sometimes, even when the UI does try to compute the size recursively, it takes it a while to update it, so it may show a smaller, temporary number for a while, until it gets around to completing the full recursive search.
So it's not surprising if the UI is giving a smaller number. Try finding the UI preference for this.