1

Background

I can use Finder to view the physical size (bytes) and logical size (on disk). This works for

files, folders (contents), but not volumes:
Size of a file Size of a folder used space on a Volume

Alternatively

I can use mdls to get the same metadata information, but that only works for files:

$ mdls Screen\ Shot\ 2018-01-25\ at\ 16.21.06.png 
_kMDItemDisplayNameWithExtensions  = "Screen Shot 2018-01-25 at 16.21.06.png"
kMDItemAlternateNames              = (
    "Screen Shot 2018-01-25 at 16.21.06.png"
)
...
kMDItemLogicalSize                 = 54319
kMDItemOrientation                 = 1
kMDItemPhysicalSize                = 57344
...
kMDItemUseCount                    = 1
kMDItemUsedDates                   = (
    "2018-01-25 00:00:00 +0000"
)

Bad luck

I've tried df and du but neither display both physical & logical sizes.

Finally, the question!

Is there a command line method to output the physical and logical file size of a folder (contents) and/or a volume (contents)?

0

You can use AppleScript to tell Finder to get the ‘size’ or ‘physical size’:

tell application "Finder" to ¬
    get (physical size of folder (POSIX file "/Applications" as alias)) ¬
        / (1000 ^ 3) ¬
        & " GB" as text

This can be ran in command line using osascript:

$ osascript -e 'tell application "Finder" to get (physical size of folder (POSIX file "/Applications" as alias)) / (1000 ^ 3) & " GB" as text'
49.212469248 GB
$ osascript -e 'tell application "Finder" to get (size of folder (POSIX file "/Applications" as alias)) / (1000 ^ 3) & " GB" as text'
55.858548673 GB

                                               

  • Beautiful! It even works for "/" and "/Volumes/Macintosh HD" (though there is less of a difference there). Thank you. It makes all the effort writing the question worthwhile. – Matt Sephton Jan 25 '18 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .