如何编写一个 bash 脚本来遍历 Parent_directory 中的每个目录并executes a command in 每个目录.
目录结构如下:
parent_directory(名称可以是任何内容 - 不遵循模式)
- 001 (directory names follow this pattern)
- 0001.txt(文件名遵循此模式)
- 0002.txt
- 0003.txt
- 002
- 0001.txt
- 0002.txt
- 0003.txt
- 0004.txt
- 003
目录数量未知。
This answer https://askubuntu.com/a/77491/26946发布者Todd https://askubuntu.com/users/27704/todd-partridge-gen2ly帮助过我。
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd" \;
The \( ! -name . \)
避免在当前目录中执行命令。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)