Reputation: 24248
I have directory tree like:
dir11/dir21/dir31......./dirn1
dir12/dir22/dir32......./dirn2
dir13/dir23/dir33......./dirn3
Depths are different. Does it possible find all paths on which exists directory with file x.txt that has length>0 ? May be need use bash script? Thanks.
Upvotes: 5
Views: 4786
Reputation: 262939
I believe GNU find can match all your criteria by itself:
$ find /top/dir -not -empty -type f -name x.txt -printf '%h\n'
The above recursively searches /top/dir
for non-empty (-not -empty
), regular (-type f
) files named x.txt
, and prints the directories leading to these files (-printf '%h\n'
).
Upvotes: 9
Reputation: 79185
Probably with find you can use:
find /top/dir -type f -name x.txt -size +1b -printf '%h\n'
Upvotes: 3
Reputation: 121710
You pretty much need that, yes...
for dir in $(find /the/root/dir -type d); do
if [ ! -f "$dir/x.txt" ]; then
continue
fi
size=$(stat -c %s "$dir/x.txt")
if [ "$size" != "0" ]; then
echo $dir
fi
done
Upvotes: 1