I've seen people mention a rename command, but it is not routinely available on Unix systems (as opposed to Linux systems, say, or Cygwin - on both of which, rename is an executable rather than a script). That version of rename has a fairly limited functionality:
rename from to file ...
它将文件名的 来自部分替换为 到,在手册页中给出的示例是:
rename foo foo0 foo? foo??
This renames foo1 to foo01, and foo10 to foo010, etc.
#!/bin/bash
# USAGE: cd FILESDIRECTORY; RENAMERFILEPATH/MultipleFileRenamer.sh FILENAMEPREFIX INITNUMBER
# USAGE EXAMPLE: cd PHOTOS; /home/Desktop/MultipleFileRenamer.sh 2016_
# VERSION: 2016.03.05.
# COPYRIGHT: Harkály Gergő | mangoRDI (https://wwww.mangordi.com/)
# check isset INITNUMBER argument, if not, set 1 | INITNUMBER is the first number after renaming
if [ -z "$2" ]
then i=1;
else
i=$2;
fi
# counts the files to set leading zeros before number | max 1000 files
count=$(ls -l * | wc -l)
if [ $count -lt 10 ]
then zeros=1;
else
if [ $count -lt 100 ]
then zeros=2;
else
zeros=3
fi
fi
# rename script
for file in *
do
mv $file $1_$(printf %0"$zeros"d.%s ${i%.*} ${file##*.})
let i="$i+1"
done