递归重命名所有子目录中的.jpg文件 [英] Recursively rename .jpg files in all subdirectories
本文介绍了递归重命名所有子目录中的.jpg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Linux系统上,我试图将许多子目录中的所有.jpg文件重命名为顺序文件名,因此每个子目录中的所有jpeg文件都重命名为0001.jpg,0002.jpg等.我有一个'重命名"命令可在单个目录中使用:
I am on a Linux system and I am trying to rename all .jpg files in many subdirectories to sequential filenames, so all the jpeg files in each subdirectory are renamed 0001.jpg, 0002.jpg, etc. I have a 'rename' command that works in a single directory:
rename -n 's/.*/sprintf("%04d",$::iter++ +1).".jpg"/e' *.jpg
我正在尝试像这样使用它:
I am trying to use it like this:
for i in ls -D; do rename -n 's/.*/sprintf("%04d",$::iter++ +1).".jpg"/e' *.jpg; done
但是对于输出,我得到了:
but for output I get this:
*.jpg renamed as 0001.jpg
用于每个子目录.我在做什么错了?
for each subdirectory. What am I doing wrong?
推荐答案
在我看来,您忘记了更改当前的工作目录,因此它看起来应该像
It seems to me you've forgot to change a current working directory so it should looks like
for i in *; do
[ -d "$i" ] || continue
pushd "$i"
# rename is here
popd
done
这篇关于递归重命名所有子目录中的.jpg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文