查找和目录递归替换文件名 [英] Find and replace filename recursively in a directory
本文介绍了查找和目录递归替换文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想它与 123_xxx.txt
开始 xxx.txt
文件夹中的所有文件重命名。
I want to rename all the files in a folder which starts with 123_xxx.txt
to xxx.txt
.
例如,我的目录有:
123_xxx.txt
123_yyy.txt
123_zzz.txt
I want to rename all files as:
xxx.txt
yyy.txt
zzz.txt
我已经看到了在这个论坛上一些有用的bash脚本,但我仍然感到困惑如何使用它为我的要求。
I have seen some useful bash scripts in this forum but I'm still confused how to use it for my requirement.
让我们假设我用:
for file in `find -name '123_*.txt'` ; do mv $file {?.txt} ; done
这是做了正确的方法是什么?
Is this the correct way to do it?
推荐答案
做这种方式:
find . -name '123*.txt' -type f -exec bash -c 'mv "$1" "${1/\/123_//}"' -- {} \;
优点:
- 没有管,不读,不打破畸形文件名的机会。
- 只有一个非标准的工具或功能:庆典
这篇关于查找和目录递归替换文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文