Skip to content

Instantly share code, notes, and snippets.

@vps2fast
Created October 3, 2014 07:39
Show Gist options
  • Save vps2fast/51e4c3ead5a9f2f563bb to your computer and use it in GitHub Desktop.
Save vps2fast/51e4c3ead5a9f2f563bb to your computer and use it in GitHub Desktop.
Script for detecting sparsed files
#!/usr/bin/perl
# based on: https://code.google.com/p/unixtoolbox/source/browse/trunk/sparse_files/checksparse.pl?r=8
# author: pavel.odintsov@gmail.com
use strict;
use warnings;
unless (scalar @ARGV == 1) {
die "Please specify path";
}
sub process_file {
my $path = shift;
unless (-f $path) {
die "It's not an file";
}
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat $path;
my $blocks_used = $blocks * 512;
my $is_sparsed = '';
if ($blocks_used < $size) {
$is_sparsed = 1;
}
if ($is_sparsed) {
print "File $path is sparsed, size: $size, actual space used: $blocks_used\n";
} else {
print "File $path is not sparsed, size: $size, actual space used: $blocks_used\n";
}
}
process_file($ARGV[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment