search through a range of directories bash script
I have written (tried to) this small bash script for searching through a range of directories.
#!/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". 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?
Thanks
if you have Bash 4.0 you can try 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`
Replace that line and you'll find all files under [ac]* named blarg.
精彩评论