1

I have a number of folders in unix (with different names) that should all have the same few file names in them. I want to find the folders that DON'T have a specific file:

For example:

A/
-->a.dat
-->b.dat
-->c.dat
B/
-->a.dat
-->b.dat
-->c.dat
C/
-->a.dat
-->c.dat

When looking for the b.dat file, how do I figure out that the C folder doesn't have it?

4

1 に答える 1

3

各ディレクトリをループし、探しているファイルがない場合は、結果のリストに追加します。

上記のファイル構造で、このスクリプトは次のようになります。

#!/bin/bash

result=()
for D in *; do
    if [ -d "${D}" ] && ! [ -f "${D}/b.dat" ]; then
        result+=("${D}")
    fi
done

echo "result is" "${result[@]}"

プリント:

result is C
于 2013-02-06T19:05:59.663 に答える