Created
October 3, 2014 07:39
-
-
Save vps2fast/51e4c3ead5a9f2f563bb to your computer and use it in GitHub Desktop.
Script for detecting sparsed files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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