从linux中的多个文件名中删除“-template”部分

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从linux中的多个文件名中删除“-template”部分相关的知识,希望对你有一定的参考价值。

我有一些名称如下的文件:

jcr-repository-template.xml
imapserver-template.xml

我想将它们重命名为:

jcr-repository.xml
imapserver.xml.

我试着用find -name "*-template.*" -exec rename -v "template" "" {} ";"

它工作但我只匹配“模板”而不是“-template”(我找不到如何)。所以现在我在每个文件名的末尾都有一个短划线字符。任何人都可以帮助我吗?

答案

在许多命令中,选项--可用于指示我可以测试的选项的结束并且它有效:

touch imapserver-template.xml
rename -v -- -template '' imapserver-template.xml

否则另一种解决方案可能是使用不以-开头的等效正则表达式模式

rename -v '(?:-template)' '' imapserver-template.xml

以上是关于从linux中的多个文件名中删除“-template”部分的主要内容,如果未能解决你的问题,请参考以下文章