【问题标题】:How to remove part of filename and add extension programmatically?如何以编程方式删除部分文件名并添加扩展名?
【发布时间】:2010-01-24 12:07:39
【问题描述】:

我在一个文件夹中有数百个文件,名称如下:

index.html?tab=This is - the file name

我想删除 "index.html?tab=" 部分并为所有文件添加扩展名 ".txt"。如何使用 Unix 命令行工具(我使用的是 MacOSX 10.6.2)来做到这一点?

【问题讨论】:

    标签: bash unix command-line


    【解决方案1】:

    在 bash 中,

    for i in index.html\?tab\=*; do mv "$i" "${i:15}.txt"; done
    

    【讨论】:

      【解决方案2】:
      for file in index.html\?*
      do
         mv "$file" "${file#*=}".txt
      done
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多