我已经(尝试)编写了这个用于搜索一系列目录的小 bash 脚本。
#!/bin/bash
shopt -s nullglob
for file in [ac]*/blarg
do
echo $file
done
此脚本在以“a”到“c”开头的目录中搜索“blarg”。 它只深入一层。我怎样才能让它遍历它可能遇到的所有目录,而不仅仅是具有首字母的目录的根目录。
此外,这个问题应该放在 stackoverflow 上还是 super 用户更合适?
谢谢
最佳答案
如果你有 Bash 4.0,你可以试试 globstar
#!/bin/bash
shopt -s nullglob
shopt -s globstar
for file in [ac]*/**/blarg
do
echo $file
done
关于linux - 搜索一系列目录 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1919355/