将文件夹中的文件重命名为序列号 [英] Renaming files in a folder to sequential numbers
本文介绍了将文件夹中的文件重命名为序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将目录中的文件重命名为序列号.基于文件的创建日期.
I want to rename the files in a directory to sequential numbers. Based on creation date of the files.
例如sadf.jpg
到0001.jpg
,wrjr3.jpg
到0002.jpg
等等上,前导零的数量取决于文件总数(如果不需要,则不需要额外的零).
For Example sadf.jpg
to 0001.jpg
, wrjr3.jpg
to 0002.jpg
and so on, the number of leading zeroes depending on the total amount of files (no need for extra zeroes if not needed).
推荐答案
尝试使用循环、let
和 printf
来填充:
Try to use a loop, let
, and printf
for the padding:
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
使用 -i
标志可防止自动覆盖现有文件,使用 --
可防止 mv
将带有破折号的文件名解释为选项.
using the -i
flag prevents automatically overwriting existing files, and using --
prevents mv
from interpreting filenames with dashes as options.
这篇关于将文件夹中的文件重命名为序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文