我相信GNU find可以自己匹配所有标准:
$ find /top/dir -not -empty -type f -name x.txt -printf '%h\n'
Run Code Online (Sandbox Code Playgroud)
上面以递归方式搜索名为的/top/dir非empty(-not -empty),regular(-type f)文件x.txt,并打印通向这些文件的目录(-printf '%h\n').
你非常需要这个,是的......
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
Run Code Online (Sandbox Code Playgroud)