I should explain a bit of Linux File System structure to explain this. Most linux file systems do something similar, but I assume ext4, which is the current default.
File System Structure
- inode is the basic block that the file system understands as a logical unit.
- A directory inode contains references to other inodes.
- A file inode contains the metadata, actual data, and references to continuation blocks, in case the file had to be stored in a non contiguous manner.
- Ext4 supports two kinds of links. Hard and Soft.
- A hard link is a reference to inode directly. Each file has atleast one hard-link, from the directory it belongs to.
- Since a directory is just a inode, with information about group of inode references, it can reference itself, or a parent. In other words, a folder can be both child and parent to the same folder.
Okay, this may be getting confusing. Let me explain. Assume you have three folders, A,B,C as follows.
C is in B.
B is in A.
Now, the fun part is, C can point to the same inode as A, creating what is sometimes called a circular reference loop. If you try recursing, you will encounter a never ending loop.
- Soft links are ordinary files that record the directory path to their target location. They are just marked on the filesystem that instead of a line of text, they should be interpreted as a link to some other location. Nautilus, for example, creates soft links when you use its 'Create link'/'Link here' options.
Hence, trying to calculate sizes recursively has its quirks. It is a bad idea to try and compute sizes recursively by default. However, properties dialogs of all decent file managers I know show recursively calculated total sizes, because that is what an ordinary user expects.
Windows has no problem?
Actually, windows uses a different file system format called NTFS, which maintains a list of all files and their size. So it can always tell the total size easily.
Then why don't we use NTFS?
It does not support the Unix notion of permissions (
rwx for owner, group, and universe separately), and that single reason makes it unfit for use as a Linux file system. Ext4 brings a lot to the table that this minor inconvenience doesn't matter to many.
Alright. Gimme the size I need.
Did you try
du stands for disk usage. It actually counts the inode blocks, taking care to not double-count them. Add up the sizes, and you have the total size.
du -hs <foldername> to find the actual size of the folder on disk. Read
man du for more info.