Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 61 jpg 的文件夹,按图片 002.jpg 到图片 062.jpg 的顺序,我想删除“图片”并按照它们当前所在的顺序正确重命名文件 01 到 61。如何我在 bash 脚本中执行此操作?
#!/bin/bash x=1 for f in * do if [ "$f" != "change_name.sh" ]; then new_name=`printf "%02d.jpg" $x` mv -v "$f" $new_name x=$((x+1)) fi done
用法:将脚本保存在change_name.sh图像的同一目录中并运行。
change_name.sh
您可以ls在运行此脚本之前创建您的目录。如果文件名的顺序正确,那很好。或者你可以ls在for循环中改变ls|sort。
ls
for
ls|sort
希望这能有所帮助。