Answer the question
In order to leave comments, you need to log in
How to create a hard link to a file?
Script renames PHOTO1.JPG files to photo0001.jpg
#!bin/bash
rename ‘y/A-Z/a-z/‘ *.JPG
rename ‘s/photo/photo000/g’ *.jpg
Answer the question
In order to leave comments, you need to log in
#!/bin/bash
for fn in *.JPG
do
fn_small=${fn,,}
num=${fn_small//[a-z.]}
mv $fn ${fn_small/$num/$(printf "%04d" $num)}
done
horror, why did I do this ...
we generate a mountain of files for the test:
#!/bin/bash
for fname in PHOTO*;
do
number=$(echo $fname | sed -r 's/PHOTO([0-9]+)\.JPG/\1/');
echo $fname - $number;
case $number in
?)
newname='photo000'$number.jpg
;;
??)
newname='photo00'$number.jpg
;;
???)
newname='photo0'$number.jpg
;;
????)
newname='photo'$number.jpg
;;
esac
echo "old: $fname new: $newname";
# mv $fname $newname
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question