【问题标题】:Remove "-template" part from multiple filenames in linux从linux中的多个文件名中删除“-template”部分
【发布时间】:2019-02-10 08:46:00
【问题描述】:

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

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】:

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

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

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

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

    【讨论】:

    • 谢谢!我用 find -name "-template." -exec rename -v -- -template '' {} ";"正如你所说,它奏效了!
    猜你喜欢
    • 2012-08-23
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 2011-05-29
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    相关资源
    最近更新 更多