gpt4 book ai didi

linux - 更改脚本重命名从生成 A0 A1 A2 A3 到 A001 A002 A003

转载 作者:太空宇宙 更新时间:2023-11-04 11:26:55 25 4
gpt4 key购买 nike

如何将文件从 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

最佳答案

有一些变化:

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

关于linux - 更改脚本重命名从生成 A0 A1 A2 A3 到 A001 A002 A003,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14151043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com