【问题标题】:Recursively find ".sh" file and then execute my .sh file on that path递归查找“.sh”文件,然后在该路径上执行我的 .sh 文件
【发布时间】:2017-12-07 00:15:22
【问题描述】:

我有一个包含子子文件夹的文件夹,一些文件夹包含 .sh 文件。我想在我看到 .sh 文件的路径中执行我的 .sh 文件。我试过了

find . -name '*.sh' 
./folder 1/folder 2/run.sh
./folder3/run.sh
./folder 4/run.sh
./folder5/run.sh

此查找功能工作正常。现在我有另一个 .sh 文件,我想在 .sh 文件路径上执行它。我试过了

find . -name '*.sh' /home/cool/Desktop/followup.sh {} ;

followup.sh 是我的文件。该命令正在当前目录中执行。但它没有在 run.sh 文件路径上执行。

我是 bash 脚本的新手。我会发出什么命令或命令?请注意,文件夹名称中有空格。

【问题讨论】:

  • 基本上你错过了-exec:应该是find . -name '*.sh' -exec /home/cool/Desktop/followup.sh {} \;
  • 此外,如果要在该文件的路径中运行脚本,请使用-execdir 而不是-execfind . -name '*.sh' -execdir /home/cool/Desktop/followup.sh {} \;
  • @hek2mgl 谢谢。 execdir 工作。
  • @hek2mgl 我在我的另一个文件夹中尝试过,但出现以下错误 chmod: cannot access ‘*.sh’: No such file or directory /home/cool/Desktop/followup.sh: ./*.sh: not found 。任何解决方法?

标签: linux bash shell


【解决方案1】:
find <parent-directory where all sub-folders with run.sh are located> -name '*.sh' -execdir /home/cool/Desktop/followup.sh {} \;

【讨论】:

  • 如果我的工作没有文件(例如/home/cool/Desktop/followup.sh),我有一个行命令来执行所有找到的.sh,它是否有效?
猜你喜欢
  • 2012-11-24
  • 2019-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-21
相关资源
最近更新 更多