[英]bash scripting - trouble renaming files in subdirectories using find / rename
I have a large series of directories and subdirectories with many jpgs in them. 我有大量的目录和子目录,其中包含许多jpg。 I need to do two things: 我需要做两件事:
I have tried to run the following commands in order: 我尝试按顺序运行以下命令:
//this creates a copy of every jpg found and appends '_m' to the end of it //这将为找到的每个jpg创建一个副本,并将'_m'附加到其末尾
find . -name '*.jpg' -execdir cp {} {}_m \;
//now again find everything with 'jpg_m' at the end and rename it as filename_m.jpg //现在再次找到所有以'jpg_m'结尾的内容,并将其重命名为filename_m.jpg
find . -name '*.jpg_m' -execdir rename -v 's/\.jpg_m/_m\.jpg/' {} \;
However the 2nd command does'nt seem to work, can someone please explain what I'm doing wrong? 但是第二条命令似乎无效,有人可以解释我在做什么错吗?
Thanks, Adi 谢谢阿迪
To rename files, you can simply use it this way rename ".jpg_m" "_m.jpg" files_to_rename
要重命名文件,只需使用这种方式即可rename ".jpg_m" "_m.jpg" files_to_rename
so, if you want to copy and rename, you can rename it this way: 因此,如果要复制和重命名,则可以通过以下方式重命名:
find . -name "*.jpg_m" -execdir rename ".jpg_m" "_m.jpg" {} \;
您为什么不一口气做到呢?
find . -name '*.jpg' -exec cp {} m_{} \; -exec rename "m_" "" {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.