0

如何将文件从 A0 A1 A2 A3 重命名为 A001 A002 A003 我有这样的重命名代码:

n=$(ls -1 | grep '^A' -c)             # find the number for A files
nfiles=$(ls -1 *.obj| grep -v '^A');  # list of all non-A files
for file in $nfiles;                  # for each of the non-A files
do
n=$(($n+1));
new_file=A$n.obj                   # new name with next available A file name
mv $file $new_file                 # rename with new file name
done
4

2 回答 2

1

有一些变化:

n=$(ls [A]* | wc -l)
nfiles=$(ls [^A]*.obj)               # list of all non-A files
for file in $nfiles;                 # for each of the non-A files
do
  n=$(($n+1));
  new_file=$(printf "A%03d.obj" $n)  # new name with next available A file name
  echo mv $file $new_file            # rename with new file name
done
于 2013-01-04T04:33:33.133 回答
0

如果原始文件是另一个名称,例如。ant.obj dog.obj ,如何更改代码重命名为 A001 A002 A003 ....

于 2013-01-04T05:28:11.117 回答