How to get the size of a folder as reported by Windows Explorer on Linux?
On Windows when you view the properties of a folder the size is calculated as follows (recursively):
- for files the length of the content counts
- symbolic links count zero
- folders themselves count zero
Is it possible to get the same result on the Linux command line?
Here are some commands from various SE posts which I already tried:
du -s -B 1 folder
du -sb folder
du -sh --apparent-size folder
ncdu
tree folder -s
The problem is they all count 4k for folders. Anyone has an idea?
Essentially, you only want to count the lengths of the contents of “real” files inside the directory; with GNU find
:
find /path/to/directory -type f -printf '%sn' | awk '{ s += $1 } END { print s }'
This finds all files under the named directory, outputs their apparent size, and calculates the sum using AWK.