加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 16:37:42 所属栏目:安全 来源:网络整理
导读:如何编写一个bash脚本,通过parent_directory中的每个目录,并在每个目录中执行一个命令。 目录结构如下: parent_directory (name could be anything – doesnt follow a pattern) 001 (directory names follow this pattern) 0001.txt (filenames follow t
如何编写一个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,所以当前目录不会在主脚本中更改。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读