如何使用bash表明,有两个子文件夹? [英] How to use bash to show folders that have two subfolders?

查看:128
本文介绍了如何使用bash表明,有两个子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Cygwin的使用bash。我有一个大文件夹(A),有许多子文件夹(B)。这些子文件夹有一个或两个子文件夹每个(C)。我想找到所有包含两个子文件夹(C),并将其输出的子文件夹(B)。

的结构如下:

  A
 B1
  C1
 B2
  C1
  C2
 B3
  C1
  C2

到目前为止,我只知道如何使用找到和管道输出的主文件夹所有子文件夹(A)。

 找到。型D> folders.txt

我怎么能只输出有两个 C 文件夹到一个文本文件,每一个文件夹的所有 B 文件夹线? (在我的例子输出应该是:

  B2
B3


解决方案

尝试使用这样的 AWK

 光盘
找 。型开发|
awk的-F /'{ARR [$ 2] ++} END {为(ARR中的一个){如果(ARR [一] == 3)打印一个}}'

或者使用庆典

 光盘
因为我在* /;做X =($ I / * /); (($ {#X [@]} == 2))及&放大器;回声$ {I%/}; DONE

I use bash via Cygwin. I have a big folder (a), with many subfolders (b). These subfolders have either one or two subfolders each (c). I want to find all the subfolders (b) that have two subfolders (c) and output them.

The structure is as follows:

a
 b1
  c1 
 b2
  c1
  c2
 b3
  c1
  c2

Thus far I only know how to use find and pipe to output ALL subfolders in the main folder (a).

find . -type d > folders.txt

How can I only output all b folders that have two c folders to a text file with one folder per line? (In my example the output should be:

b2
b3

解决方案

Try doing this using :

cd a
find . -type d |
awk -F/ '{arr[$2]++}END{for (a in arr) {if (arr[a] == 3) print a}}'

Or using :

cd a
for i in */; do x=( $i/*/ ); (( ${#x[@]} == 2 )) && echo "${i%/}"; done

这篇关于如何使用bash表明,有两个子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆