【问题标题】:linux rename file names recursivelylinux递归重命名文件名
【发布时间】:2020-11-23 02:28:35
【问题描述】:

我需要递归地将 bash-sdl2-compile.sh 重命名为 compile.sh
尝试使用“重命名”失败,显然安全功能不允许使用“bash”字,即

find ./ -name "bash-sdl2-compile.sh" -print0 | xargs -0 rename "bash-sdl2-compile.sh" "bash-sdl2-compile/compile"

错误消息:在(用户提供的代码)使用“严格的 subs”时不允许使用裸词“bash”。 xargs:重命名:以状态 255 退出;中止

如何递归重命名 linux 文件?

    dir1
       |_project1
                |_ bash-sdl2-compile.sh
    dir2
       |_project2
                |_ bash-sdl2-compile.sh
    dir3
       |_project3
                |_ bash-sdl2-compile.sh
  . . . 

因此,将每个“bash-sdl2-compile.sh”重命名为“compile.sh”

【问题讨论】:

  • 看起来所有文件最终都只有一个名称,不是吗?
  • 能否提供搬家前后的目录样本?
  • 我有 20 个子目录,每个子目录都有一个名为 "bash-sdl2-compile.sh" 的文件,我需要将其更改为 "compile.sh" 我显示的代码发布在“堆栈服务器”上
  • @jwzumwalt :在我看来,您的错误消息好像是由 Perl 程序发出的。除此之外,您发布的代码中没有裸词 bash

标签: linux bash file-rename mv


【解决方案1】:

不用xargsfind就够了:

find . -name bash-sdl2-compile.sh -execdir mv -i {} compile.sh ";"

(在尝试之前备份整个树)

【讨论】:

  • 这不起作用,有错误,find 。 -name bash-sdl2-compile.sh -execdir mv {} bash-sdl2-compile/compile ";" 输出:mv: 无法将 './bash-sdl2-compile.sh' 移动到 'bash-sdl2 -compile/compile': 没有这样的文件或目录
  • 如果您真的想将所有bash-sdl2-compile.sh 文件放在一个目录中,从而用找到的最后一个文件覆盖所有文件,则将-execdir 更改为-exec。我不确定这真的是你想要的(因此我的回答),你应该先备份你的文件。
  • 我正在尝试递归地向下移动目录并在其原始目录中找到“file1”并重命名为“file2”。
  • 请修改您的问题并解释您想要什么。特别是:什么是file2?是 bash-sdl2-compile/compile 吗?还是 bash-sdl2-compile/compile/bash-sdl2-compile.sh?或者是其他东西?不要只回答我,请编辑您的问题,以便每个人都清楚。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
  • 2016-04-18
  • 2014-08-11
  • 2020-12-21
  • 2014-03-03
  • 2017-08-18
相关资源
最近更新 更多