[clug] Disk vs file size
Tony Lewis
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
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
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
1465700352
tony at neutrino:~$ du -sh tmp/
1.4G tmp/
Yeah (holds up thumb, squints) looks about right.
Oh, wait, can you use 'du'?
tony at neutrino:~$ du -s --block-size=1 tmp/
1465724928 tmp/
This matches the size, include directories:
tony at neutrino:~$ ( find tmp/ -print0 | xargs -0 stat --printf '( %b
* %B ) + ' ; echo 0 ) | bc
1465724928
Tony
More information about the linux
mailing list