これはトリッキーです。
いい解決策が思いつきません。しかし、それにもかかわらず、ここに解決策があります。ディレクトリまたはファイル名に改行が含まれている場合、これは機能しないことが保証されており、他の特殊文字が含まれている場合は機能しないことが保証されていることに注意してください。(私はあなたの質問のサンプルでのみテストしました。)
また、-maxdepth
サブディレクトリも検索する必要があると言ったので、 a は含めませんでした。
#!/bin/bash
# Create an associative array
declare -A excludes
# Build an associative array of directories containing the file
while read line; do
excludes[$(dirname "$line")]=1
echo "excluded: $(dirname "$line")" >&2
done <<EOT
$(find . -name "*protein.fasta" -print)
EOT
# Walk through all directories, print only those not in array
find . -type d \
| while read line ; do
if [[ ! ${excludes[$line]} ]]; then
echo "$line"
fi
done
私にとって、これは次を返します:
.
./dir3
./dir4
これらはすべて、一致するファイルを含まないディレクトリです*.protein.fasta
。もちろん、最後echo "$line"
のディレクトリは、これらのディレクトリで行う必要があるものに置き換えることができます。
別の方法:
本当に探しているのが、どのサブディレクトリにも一致するファイルを含まない最上位ディレクトリのリストだけである場合は、次の bash ワンライナーで十分な場合があります。
for i in *; do test -d "$i" && ( find "$i" -name '*protein.fasta' | grep -q . || echo "$i" ); done