简体   繁体   English

搜索一系列目录bash脚本

[英]search through a range of directories bash script

I have written (tried to) this small bash script for searching through a range of directories. 我已经编写(尝试)了这个小bash脚本,用于在一系列目录中进行搜索。

#!/bin/bash
shopt -s nullglob
for file in [ac]*/blarg
do 
   echo $file
   done

This script searches through directories starting with "a" through "c" for "blarg". 该脚本在以“ a”至“ c”开头的目录中搜索“ blarg”。 It only goes one level deep. 它只会深入一层。 How can I make it step through all directories it might encounter, and not just the root of the directories with the starting letter. 如何使它逐步遍历它可能遇到的所有目录,而不仅仅是带有起始字母的目录的根目录。

Also, is this question supposed to go here at stackoverflow or would superuser be more suitable? 另外,这个问题应该在stackoverflow上解决还是超级用户更合适?

Thanks 谢谢

if you have Bash 4.0 you can try globstar 如果您拥有Bash 4.0,则可以尝试globstar

#!/bin/bash
shopt -s nullglob
shopt -s globstar
for file in [ac]*/**/blarg
do 
   echo $file
done

on the command line ths will do your purpose.so why to go for a script? 在命令行上,这将达到您的目的。那么,为什么要使用脚本呢?

find ./[ac]*/ -name "blarg"

if you still need a script: 如果您仍然需要脚本:

#!/bin/bash
shopt -s nullglobi
for file in `find ./[ac]*/ -name "blarg"`
do
echo $file
done
echo `find blarg`

替换该行,您将在[ac] *下找到名为blarg的所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM