Created
May 21, 2017 05:45
-
-
Save fbarriga/0cc62c6612cc8007b41786b3ab939d64 to your computer and use it in GitHub Desktop.
Summary of directory fragmentation
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 -w | |
# stolen from: https://forums.gentoo.org/viewtopic-p-3089351.html | |
#this script search for frag on a fs | |
use strict; | |
#number of files | |
my $files = 0; | |
#number of fragment | |
my $fragments = 0; | |
#number of fragmented files | |
my $fragfiles = 0; | |
#search fs for all file | |
open (FILES, '-|', "find '$ARGV[0]' -xdev -type f -print0"); | |
$/ = "\0"; | |
while (defined (my $file = <FILES>)) { | |
open (FRAG, "-|", "filefrag", $file); | |
my $res = <FRAG>; | |
if ($res =~ m/.*:\s+(\d+) extents? found/) { | |
my $fragment = $1; | |
$fragments += $fragment; | |
if ($fragment > 1) { | |
$fragfiles++; | |
} | |
$files++; | |
} else { | |
print ("$res : not understand for $file.\n"); | |
} | |
close (FRAG); | |
} | |
close (FILES); | |
print ( $fragfiles / $files * 100 . "% non contiguous files, " . $fragments / $files . " average fragments.\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment