根据序列号重命名匹配的文件 [英] Rename matching files based on a serial number
本文介绍了根据序列号重命名匹配的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一堆Mac屏幕截图文件:
Assuming I have a bunch of files that are mac screenshots:
Screen Shot 2018-11-09 at 12.37.37 PM.png
Screen Shot 2018-11-10 at 4.53.02 PM.png
Screen Shot 2018-11-10 at 9.19.19 PM.png
我想用mv将它们标记为:
And I want to use mv to label them to:
Screen_0.png
Screen_1.png
Screen_2.png
我想出的部分命令:
find . -name "Screen*" -exec sh -c 'mv "$1" "Screen_$2"' _ {} ??? \;
如何执行命令以使其可以按数字标记图像?还是我不得不求助于更复杂的文件.
How to implement the command so that it can label image by digits? or do I have to resort to a more complicated file.
推荐答案
我认为不可能以您想要的方式传递序列号xargs
.而是使用一个简单的循环:
I don't think it is possible to pass a sequence number xargs
in the way you want. Use a simple loop instead:
#!/bin/bash
for file in Screen*.png; do
[[ -f $file ]] || continue # skip if not a regular file
mv "$file" "Screen_$((count++)).png"
done
这篇关于根据序列号重命名匹配的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文