【问题标题】:Batch rename files that match a rule批量重命名符合规则的文件
【发布时间】:2014-09-22 12:38:33
【问题描述】:

我有一个来自旧 iOS 项目的文件夹,其中包含许多类似于

的文件结构
image.png
image@2x.png
another-image.png
another-image@2x.png

但是,由于该项目现在只需要 @2x.png 图像,因此我删除了名称中没有 @2x 的所有文件。

但是我现在想知道如何轻松地从所有文件名中删除 @2x(大约有 300 张图像)

我所在的环境是 OSX Mavericks,所以任何自动机/终端命令都可以。

【问题讨论】:

    标签: macos shell file-io automator


    【解决方案1】:
    for name in *@2x*; do mv $name ${name%@2x*}${name#*@2x}; done
    

    【讨论】:

      【解决方案2】:

      已考虑包含空格的名称:

      IFS=$'\n'
      for f in $(find . -name \*@2x.png)
      do
          newf="$(echo "$f" | sed s/@2x//)"
          mv "$f" "$newf"
      done
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-19
        • 2017-04-20
        • 2012-09-02
        • 1970-01-01
        • 2018-04-26
        • 1970-01-01
        • 2017-02-18
        相关资源
        最近更新 更多