【问题标题】:How to rename files in different directories with the same name using find如何使用find重命名不同目录中具有相同名称的文件
【发布时间】:2019-05-04 15:44:46
【问题描述】:

我在这样的不同目录中有名为 test.txt 的文件

./222/test.txt
./111/test.txt

我想将所有test.txt 重命名为info.txt

我试过用这个

find . -type f -iname 'test.txt' -exec mv {} {}info \;

我收到test.txtinfo

【问题讨论】:

    标签: linux shell command-line terminal


    【解决方案1】:

    您的想法是正确的,但您需要使用-execdir 而不是仅使用-exec 来简化此操作。

    find . -type f -iname 'test.txt' -execdir mv {} info.txt ';'
    

    这类似于-exec,不同之处在于给定的shell命令以找到的路径名的目录作为其当前工作目录执行,而{}将包含找到的路径名的基本名称而不包含其路径。另请注意,该选项是非标准选项(不符合 POSIX)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-27
      • 2012-12-11
      • 2016-07-22
      • 2019-03-15
      • 2022-06-14
      • 2015-07-27
      • 2020-12-23
      • 1970-01-01
      相关资源
      最近更新 更多