Always when I run ls -ld /dir the output give me the size = 512 even if there are files in it or not.
but when I run du -sh the output give me the actual size of the directory including its content.
Always when I run ls -ld /dir the output give me the size = 512 even if there are files in it or not.
but when I run du -sh the output give me the actual size of the directory including its content.
Actually if you would have many files in your directory you would get a larger number there: when I create 10000 empty files in a new directory that number goes from 4096 to 262144.
The starting size is depending on the filesystem and blocksize as specified when creating the filesystem. It is an indication of how much metadata the directory is holding (for the files and directories contained in it), not how much data the files in a directory are holding.
To compare: A directory with 10000 empty files
ls -ld . --> 262144
du -sh . --> 260K
A directory with 10000 files of 100000 bytes each:
ls -ld . --> 262144
du -sh . --> 977M
Metadata is the same size for both set of files (they also have exactly the same names).