[clug] Disk vs file size
tony at lewistribe.com
Thu Aug 8 08:23:21 UTC 2019
On 8/8/19 5:12 pm, Andrew Janke via linux wrote:
> Hi all,
> Let's say I have a filesystem that has a blocksize of 1Mb. Yes, you
> read that right. And I happened to know that there are a lot of very
> small files in there.
> 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
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
( find /some/path -print0 | xargs -0 stat --printf '( %b * %B ) + '
; echo 0 ) | bc
Note, this will include filesystem entries for directories themselves,
which I understand take some space. If you don't want that, filter them
out using the following command:
( find /some/path -type f -print0 | xargs -0 stat --printf '( %b *
%B ) + ' ; echo 0 ) | bc
tony at neutrino:~$ ( find tmp/ -type f -print0 | xargs -0 stat
--printf '( %b * %B ) + ' ; echo 0 ) | bc
tony at neutrino:~$ du -sh tmp/
Yeah (holds up thumb, squints) looks about right.
Oh, wait, can you use 'du'?
tony at neutrino:~$ du -s --block-size=1 tmp/
This matches the size, include directories:
tony at neutrino:~$ ( find tmp/ -print0 | xargs -0 stat --printf '( %b
* %B ) + ' ; echo 0 ) | bc
More information about the linux