I have to move the 20TB file system with a couple of million of files to a ZFS file system. So I would like to get an idea of the file sizes in order to make a good block size selection.
My current idea is to `stat --format="%s" each file and then divide the files into bins.
#!/bin/bash
A=0 # nr of files <= 2^10
B=0 # nr of files <= 2^11
C=0 # nr of files <= 2^12
D=0 # nr of files <= 2^13
E=0 # nr of files <= 2^14
F=0 # nr of files <= 2^15
G=0 # nr of files <= 2^16
H=0 # nr of files <= 2^17
I=0 # nr of files > 2^17
for f in $(find /bin -type f); do
SIZE=$(stat --format="%s" $f)
if [ $SIZE -le 1024 ]; then
let $A++
elif [ $SIZE -le 2048 ]; then
let $B++
elif [ $SIZE -le 4096 ]; then
let $C++
fi
done
echo $A
echo $B
echo $C
The problem with this script is that I can't get find
to work inside a for-loop.
Question
How to fix my script?
And is there a better way to get the all the file sizes of a file system?