1
This commit is contained in:
2019-11-02 23:51:02 +03:00
commit 8388bd9c05

35
script.sh Normal file
View File

@@ -0,0 +1,35 @@
#!bash
PERL_SCRIPT=$(cat <<'EOF'
@files = split(/:/, $ARGV[0]);
@new_files = ();
foreach $file (@files) {
if ($file =~ m#^\./.+\.(jpe?g|png|gif)$#) {
($mtime) = (stat($file))[9];
$ext = $1;
$new_file = "./$mtime.$ext";
if ($new_file eq $file) {
next;
}
while (grep $_ eq $new_file, @new_files) {
if (! defined $suffix) {
$suffix = "-1";
} else {
$suffix = $suffix - 1;
}
$new_file = "./$mtime$suffix.$ext";
}
push(@new_files, $new_file);
$file =~ s#([ \(\)])#\\$1#g;
print "mv -n \"$file\" $new_file\n";
undef $suffix;
}
}
$count = @new_files;
print "echo \"Renamed: $count\"\n";
EOF
)
renamer() {
find . -maxdepth 1 -type f -print | tr '\n' ':' | xargs -I{} -- perl -e "$PERL_SCRIPT" '{}' | xargs -n1 -I{} -- bash -c '{}'
}