击:列出所有只包含两个子文件夹的目录:文件夹1和文件夹2?

编程入门 行业动态 更新时间:2024-10-28 00:19:40
本文介绍了击:列出所有只包含两个子文件夹的目录:文件夹1和文件夹2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

作为标题,有人可以帮助回答这个只使用Bash?

As in the title, can someone help to answer this only using the Bash?

我花了一些时间不能弄明白。谢谢你。

I spent some time can't figure it out. Thanks.

推荐答案

下面应该列出只包含两个文件夹的目录文件夹1 和文件夹2 。

The following should list the directories containing only two folders folder1 and folder2.

for i in $(find . -type d); do count=$(find $i -mindepth 1 -maxdepth 1 -type d | wc -l); [ $count -eq 2 ] && [ -d $i/folder1 ] && [ -d $i/folder2 ] && echo $i ; done

以上不会理会,如果文件夹有其他的文件的。如果你想确保只有目录文件夹1 和文件夹2 ,说:

The above wouldn't care if the folders have other files. If you want to ensure only directories folder1 and folder2, say:

for i in $(find . -type d); do count=$(find $i -mindepth 1 -maxdepth 1 | wc -l); [ $count -eq 2 ] && [ -d $i/folder1 ] && [ -d $i/folder2 ] && echo $i ; done

[但是要注意,上述可能无法在目录名称空间的工作。]

[Be warned that the above might not work with spaces in directory names.]

更多推荐

击:列出所有只包含两个子文件夹的目录:文件夹1和文件夹2?

本文发布于:2023-10-08 23:55:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   两个   目录

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!