I have a bash script that renames files in a folder according to input from a command prompt:
echo "Please rename and press enter" read rename
if [ -z "$rename" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "rename is $rename\n" count=1
for i in *.jpg; do
j=printf "%04d" $count
j="$rename"$j".jpg"
count=$((count + 1))
mv "$i" $j
done
fi
shift
done
How can I modify this script so that the files in the folder are renamed according to their size?
If I sort the files according to size, they will look like this in the folder:
a009 978kb
a001 567kb
a003 499kb
a008 432kb
So I want the resulting files to be renamed:
a001 978kb
a002 567kb
a003 499kb
a004 432kb
j=printf "%04d" $count
would give you an%04d: no such job
error. You've forgotten$(...)
. Also, this line and the next could be writtenprintf -v j "%s%04d.jpg" "$rename" "$count"
inbash
. – Kusalananda Apr 10 '20 at 10:01