How to get the size of a Linux or Mac OS X directory from the command-line.

How to get the size of a Linux or Mac OS X directory from the command-line.

du used in OS X reports size with 512-byte blocks — the sizes are essentially rounded up to the next 512-byte value. This tells you the space on disk, which is larger than the amount of data. If you have a lot of small files, the difference can be large.

du – tells the disk use not the file size.

This is the value with regular du. It’s in 512-byte blocks:

248 .

The -h flag results in a more readable number, in kilobytes. As expected, it’s half the number of 512-byte blocks:

124K .

Finally, you can use find and awk to give you the sum of actual bytes in the files. This is kind of slow, but it works:

60527

This value matches exactly the number reported by Finder’s Get Info window.It’s significantly smaller than the value reported by du.

Show the size of a single file

Show the size of the contents of a directory, each sub-directory, and each individual file:

Show the size of the contents of a directory:

du -sch if you want something more easily readable

You can use du -ah . which displays sizes of all files and directories recursively.

This can be combined with sort, so you’ll see the top-20 biggest directories in the current folder: