Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

msephton

macrumors 6502
Original poster
Jan 6, 2004
462
199
United Kingdom, Europe
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:

WpwJL.png
GqRWb.png

0LXtp.png


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

Code:
    $ 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)?
 
Volume contents can be done with a combination of setting the BLOCKSIZE environment variable and using 'df'.

Code:
$ export BLOCKSIZE=1000000
$ df
Filesystem    1000000-blocks   Used Available Capacity iused               ifree %iused  Mounted on
/dev/disk1s1          250284 228922     18544    93% 1485373 9223372036853290434    0%   /

My Finder says: Capacity 250.14, Available 43.8 (25.25 purgeable), used 228.78.
43.8-25.25 = 18.55 which is the number shown here.

Even though the man page for 'du' says it honors the BLOCKSIZE environment variable, my testing shows it does not. So that's the problem with du I think showing you folder sizes. It's always report in power-of-2 units instead of the power-of-10 units that Finder uses.
 
  • Like
Reactions: msephton
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.