Quote:
Originally Posted by epoh
Is there a way to search the filesystem for sparse files?
|
You can do that by scripting. Using the
stat command you can retrieve the total size of files in bytes and the actually allocated blocks. Comparing these two values (the latter multiplied by the block size) when the size of allocated blocks is smaller than the total size of the file, you can guess it is a sparse file. I've written a little script in bash to do this:
Code:
#!/bin/bash
gap=0
block_size=$(stat -c %B $0)
while read line
do
size_in_bytes=$(echo $line | cut -f 1 -d \ )
block_allocated=$(echo $line | cut -f 2 -d \ )
file=$(echo $line | cut -f 3- -d \ )
if [ $(expr $block_allocated \* $block_size) -lt $size_in_bytes ]
then
echo $file
gap=$(( gap + ( $size_in_bytes - $block_allocated * $block_size ) / 1000 ))
fi
done < <( find /var -type f -exec stat -c "%s %b %n" '{}' \; )
echo Rough estimate of total unallocated space in sparse files is: $gap k
It also gives you the total amount (in kbytes) of unallocated block in sparse files, that is a rough estimate of the gap between the output of df and du. This should bring to the missing 200 Mb. Maybe...
