📌  相关文章
📜  顺序重命名文件 linux - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:50:39.761000             🧑  作者: Mango

代码示例1
### Try to use a loop, let, and printf for the padding:
# using the -i flag prevents automatically overwriting existing files, 
# using -- prevents mv from interpreting filenames with dashes as options.

a=1
for i in *.jpg; do
  new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1
done

# Here's the same example as a 1-liner:
for i in *.jpg; do new=$(printf "%04d.jpg" "$a"); mv -i -- "$i" "$new"; let a=a+1; done