【问题标题】:How to recursively remove file extension from file?如何从文件中递归删除文件扩展名?
【发布时间】:2020-03-25 12:43:03
【问题描述】:

所以我只是运行以下命令为一堆文件添加文件扩展名。我以为我会一个一个撤消它们,但结果我需要一次全部撤消它们,我该如何撤消呢?

find . -name '*.targetFileType' -type f -exec mv '{}' '{}'.not \;
  • 文件之前是:aFile.targetFileType
  • 现在是:aFile.targetFileType.not

我需要将它返回给 aFile.targetFileType

【问题讨论】:

标签: bash shell find file-extension


【解决方案1】:

我已经设法扭转:

for f in $(find . -name '*.not' -type f); do mv ${f} $(echo ${f} | sed 's/.not//g'); done;

【讨论】:

  • 请注意,无需启动额外进程即可将 file.not 转换为 file。尝试echo mv "${f}" "${f%.not}" 并在您确定它正常工作时删除echo。祝你好运。
  • 当文件名以- 开头时,这将被视为一个选项。使用mv -- "${f}" "${f%.not}"
猜你喜欢
  • 2020-06-02
  • 1970-01-01
  • 2012-06-29
  • 1970-01-01
  • 2019-10-18
  • 2012-11-29
  • 2013-03-14
  • 1970-01-01
  • 2014-07-26
相关资源
最近更新 更多