我通过 Cygwin 使用 bash。我有一个大文件夹 (a),有很多子文件夹 (b)。这些子文件夹各有一个或两个子文件夹 (c)。我想找到所有有两个子文件夹 (c) 的子文件夹 (b) 并输出它们。
结构如下:
a
b1
c1
b2
c1
c2
b3
c1
c2
到目前为止,我只知道如何使用 find
和管道输出主文件夹 (a) 中的所有子文件夹。
find . -type d > folders.txt
如何只将所有包含两个 c
文件夹的 b
文件夹输出到一个文本文件,每行一个文件夹? (在我的例子中,输出应该是:
b2
b3
最佳答案
尝试使用 awk 执行此操作:
cd a
find . -type d |
awk -F/ '{arr[$2]++}END{for (a in arr) {if (arr[a] == 3) print a}}'
或使用 bash :
cd a
for i in */; do x=( $i/*/ ); (( ${#x[@]} == 2 )) && echo "${i%/}"; done
关于bash - 如何使用 bash 显示有两个子文件夹的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14912513/