2017-08-12 65 views
0

我有一个目录和文件看起来像这样使用Linux递归更改文件名?

/Folder/A/12 3ER This.docx 
/Folder/A/12 3ER Namespace.docx 
/Folder/A/12 QW Blah.docx 
/Folder/A/12 QW BlahBlah.docx 
/Folder/B/12 3ER Annoying.docx 
/Folder/B/12 3ER Were.docx 
/Folder/B/12 QW Stack.docx 
/Folder/B/12 QW Overlow.docx 
... 

我想所有包含3ER文件重命名为_My_

因此,目录和文件应该看起来像

/Folder/A/12_My_This.docx 
/Folder/A/12_My_Namespace.docx 
/Folder/A/12 QW Blah.docx 
/Folder/A/12 QW BlahBlah.docx 
/Folder/B/12_My_Annoying.docx 
/Folder/B/12_My_Were.docx 
/Folder/B/12 QW Stack.docx 
/Folder/B/12 QW Overlow.docx 
... 

哪有我在Linux上这样做?

+0

有关如何使用操作系统而不是如何编写软件的问题,更适合[unix.se] SE或[SuperUser](https://superuser.com/)。这就是说 - 你可能会发现[BashFAQ#30](http://mywiki.wooledge.org/BashFAQ/030)有趣;它演示的内容和你需要的仅仅是使用不同的[参数扩展](http://wiki.bash-hackers.org/syntax/pe)。 –

+0

这可以说是[搜索+替换文件名中的字符串]的重复(https://stackoverflow.com/questions/7171659/searchreplace-strings-in-filenames)。 –

回答

1
find . -name '* 3ER *' -print0 | while IFS= read -r -d '' filename; do 
    mv -- "$filename" "${filename// 3ER /_My_}" 
done