0

I have a directory on my ext4 partition with lots of rather small files. How can I figure out how much space would they use if I copy them to a file system with another cluster size (without actually copying them)? Like a FAT16 with 32KB cluster size.

1

I have no idea if there is a specific tool for that, but if I'd really want to figure it out, I'd make something like (in a script/program, of course) : count the files and multiplicate that by the cluster size. Of course, I would need to check their "range" (I mean see their size and check if it would take 4, 8, 32 or 64 KB cluster-wise).

It's just an idea, I very well could be wrong. But unless someone else know a program that does it for you, you could at least work easily enough on an estimate.

0

Here is a bash/awk script for that:

#!/bin/bash
find . -type f -printf '%s\n' | awk '
    function ceil(number) {
        if (number == int(number)) {
            return (number);
        }
        return int(number) + 1;
    }

    function ceilWithUnit(number, unit) {
        return ceil(number / unit) * unit;
    }

    BEGIN {
        blockSize = 32 * 1024;
        fileSizeSum = 0;
        diskUsage = 0;
    }
    {
        diskUsage += ceilWithUnit($0, blockSize);
        fileSizeSum += $0;
    }
    END {
        printf("File count: %u\n", NR);
        printf("Average size: %.2f KB\n", fileSizeSum / NR / 1024);
        printf("Disk usage with %d bytes blocks: %.2f MB\n", blockSize, diskUsage / 1024 / 1024);
    }
'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.