Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How is that possible? The system says I've got almost 250M allocated to /var, but if you actually check disk usage of var it says I've got 40megs. Where is the 200megs? What am I missing here? This server is gonna die in a fiery crash pretty soon if I can't figure this out. This is, obviously, an old system, with no other storage available to it. Even if there was, I cannot expand the filesystem while it's online, since it's running Redhat 7.2.
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...
Tried the script but i'm getting errors that -c isn't a valid flag. i'll have to look into it some more.
Quote:
Originally Posted by colucix
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.