Existem várias soluções, algumas dependendo do sistema operacional:
Rename multiple files, groups of files
1) rename -- Debian version and RedHat version differ, q.v.
(try package util-linux:
http://en.wikipedia.org/wiki/Util-linux)
2) ren -- RedHat relatives
3) renameutils -- package contains qmv, imv, icp, qcp, and deurlname
4) mved -- (circa 2006; good as of 2015.05), perl
http://raf.org/mved/
(An earlier shell version may be available.)
5) rename -- perl builtin library routine (DIY)
6) mmv -- move/rename/copy/append/link multiple files by wildcard patterns
7) gprename - batch rename using a GUI
8) krename - batch rename using a GUI
Por exemplo, esse código no arquivo s1 demonstra mved:
# Set up environment.
pl " Input data file of names $FILE:"
head $FILE
i=0
while IFS='' read -r file
do
(( i++ ))
# echo " Name $i: $file"
touch "$file"
done < $FILE
pl " Files to consider renaming:"
ls -1 *.doc
pl " Expected output:"
cat $E
# "Order21039 Internal Document.doc" -> "Order21039.test.doc"
pl " Verbose execution and file list:"
mved -v "??????????*.doc" ==========.test.doc
pe
ls -1 *.doc
produz:
Input data file of names data1:
Order21039 Internal Document.doc
Order33920 New Order.doc
Order39307 Exam.doc
-----
Files to consider renaming:
Order21039 Internal Document.doc
Order33920 New Order.doc
Order39307 Exam.doc
-----
Expected output:
Order21039.test.doc
Order33920.test.doc
Order39307.test.doc
-----
Verbose execution and file list:
mv Order21039 Internal Document.doc Order21039.test.doc
mv Order33920 New Order.doc Order33920.test.doc
mv Order39307 Exam.doc Order39307.test.doc
Order21039.test.doc
Order33920.test.doc
Order39307.test.doc
Em um sistema como:
OS, ker|rel, machine: FreeBSD, 11.0-RELEASE-p9, amd64
bash GNU bash 4.4.12
Alguns detalhes para o código (perl) mved:
mved carefully rename multiple files (man)
Path : ~/bin/mved
Version : 1.4
Length : 495 lines
Type : Perl script, ASCII text executable
Shebang : #!/usr/bin/env perl
Help : probably available with -h
Home : http://raf.org/mved/ (doc)
Modules : (for perl codes)
warnings 1.23
strict 1.08
Getopt::Std 1.10
A sequência de chamada para mved inclui um "caractere curinga" local, "=", que representa o resultado correspondente da correspondência com caracteres curinga na primeira expressão.
felicidades, drl