Why doesn't ls -lh show the total size of all the files and directories in each directory?

1

1

For example, it shows the kernel as being 18M but the Applications folder as being 3.8K

BSD/Darwin

Igorio

Posted 2011-06-23T23:01:38.107

Reputation: 688

Answers

3

According to the man page for ls:

List information about the FILEs (the current directory by default).

ls is intended to show the size of the files on the file system, not to show the usage of a directory. du will show total usage of a file system object.

So ls is doing what it is supposed to do. While your Applications directory may contain files that use more than 3.8K, the Applications directory itself is really only 3.8K on the disk.

Kirk

Posted 2011-06-23T23:01:38.107

Reputation: 2 182

1

Because you're not on Windows, where the world pretends that directories have no space cost, and all directories are zero length. (Some parts of the Windows world pretend that the size of a directory is the cumulative size of all of the things contained in the directory.)

On Unices and Linux, the ls -l command, when displaying a directory entry that points to another directory, shows the size of the directory. It shows the amount of space devoted to actually storing the entries in the directory itself. For each directory entry, ls -l always shows the size of the node pointed to by that entry, be it file, symbolic link, or directory.

JdeBP

Posted 2011-06-23T23:01:38.107

Reputation: 23 855