/usr/bin/magicsort is in magicrescue 1.1.8-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/usr/bin/env perl
use strict;
my $dir = shift;
if (!$dir or !chdir($dir)) {
print "Usage: magicsort DIRECTORY\n",
"Will invoke your system's file(1) utility to categorize all the files found\n",
"by magicrescue.\n";
exit 1;
}
opendir DH, "." or die "opening $dir: $!\n";
while (defined(my $file = readdir DH)) {
next unless -f $file;
open FILE, "-|", "file", $file or die "Executing file: $!\n";
my $idstring = <FILE>;
close FILE;
chomp $idstring;
$idstring =~ s{[/\x00-\x1F]}{_}g;
if (length($idstring) - 3 < length($file)) {
print STDERR "Invalid idstring: $idstring";
next;
}
my $dir = substr($idstring, length($file) + 2);
mkdir $dir;
rename $file, "$dir/$file" or warn "Cannot move $file: $!\n";
}
|