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

问题描述 投票:0回答:1

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

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

我想将它们重命名为:

jcr-repository.xml
imapserver.xml.

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

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

linux bash pattern-matching rename filenames
1个回答
1
投票

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

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

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

rename -v '(?:-template)' '' imapserver-template.xml
© www.soinside.com 2019 - 2024. All rights reserved.