[clug] Disk vs file size

Tony Lewis tony at lewistribe.com
Thu Aug 8 13:11:05 UTC 2019


On 8/8/19 9:56 pm, Andrew Janke via linux wrote:
>>> Is there an each way to report how much disk space this is costing me?
>>> All I can think of is using du or ls across the thing and then back
>>> calculating.  Also, I don't think I have df access.
>> Can you use stat?
>>
>> "stat -c '%b %B' filename" gives the number of blocks and the size in
>> bytes of each block:
>>
>>       $ stat -c '%b %B' /etc/passwd
>>       8 512
>>
>> Combine with rough and ready use of find, xarg and bc, and the following
>> *might* just give you the size in bytes of the recursive contents of a
>> directory:
>>
>>       ( find /some/path -print0 | xargs -0 stat --printf '( %b * %B ) + '
>> ; echo 0 ) | bc
> Thanks both, it would seem that is giving some sensical answers, but
> it would seem that find is assuming a block size of 512 as that's
> what's being returned and I'm not convinced this is true...

No, find is not, stat is reading that, with the '%B' field in the 
--printf argument

Tony



More information about the linux mailing list