本文介绍了击:列出所有只包含两个子文件夹的目录:文件夹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?
发布评论