bash – 如何去每个目录并执行命令?

如何编写一个bash脚本,通过parent_directory中的每个目录,并在每个目录中执行一个命令。

目录结构如下:

parent_directory (name could be anything – doesnt follow a pattern)

  • 001 (directory names follow this pattern)
    • 0001.txt (filenames follow this pattern)
    • 0002.txt
    • 0003.txt
  • 002
    • 0001.txt
    • 0002.txt
    • 0003.txt
    • 0004.txt
  • 003
    • 0001.txt

the number of directories is unknown.

您可以执行以下操作,当前当前目录为parent_directory:
for d in [0-9][0-9][0-9]
do
    ( cd $d && your-command-here )
done

(和)创建一个subshel​​l,所以当前目录不会在主脚本中更改。

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...