列出具有指定深度的文件夹的所有子目录 [英] List all subdirectories of a folder with with an specified depth
问题描述
我想列出一个文件夹的所有子目录,它们的深度仅为2。到目前为止,通过查看以前的问题和用户答案,我得出了此代码,
I want to list all sub-directories of a folder which their depth is only 2. So far by looking at previous questions and users answers I come up to this code,
i=0
for directory in `find ./input -maxdepth 3 -type d -mindepth 2 `
do
arr[i]=$directory
let "i += 1"
echo $directory
done
我在Fedora机器上运行此代码,它给了我正确答案,但是当我在centOS中运行它时,它不起作用。实际上-maxdepth有效,但-mindepth无效。
I run this code in Fedora machine and it gave me correct answers, but when I run it in centOS, it is not working. Actually -maxdepth works but not -mindepth.
在Fedora中更具体,输出如下:
to be more specific in Fedora the output is like this:
-。/ input /葡萄球菌/ 200
-./input/ Staphylococcus/200
-.. / input /金黄色葡萄球菌/ 50
-./input/ Staphylococcus/50
-。/输入/葡萄球菌/100
-./input/ Staphylococcus/100
-./输入/葡萄球菌/150
-./input/ Staphylococcus/150
-./输入/ Neisseria_meningitidis / 200
-./input/Neisseria_meningitidis/200
-。/ input / Neisseria_meningitidis / 50
-./input/Neisseria_meningitidis/50
-。/ input / Neisseria_meningitidis / 100
-./input/Neisseria_meningitidis/100
-。/ input / Neisseria_meningitidis / 150
-./input/Neisseria_meningitidis/150
这是我的期望输出,在centOS中,输出包含以下列表:
which is my desire output and in in centOS the output contains these list as well as some other directories with longer depth.
另一个有趣的事情是当我运行
Another interesting thing is when I run
./ input- mindepth 2 -maxdepth 2 -type d
./input -mindepth 2 -maxdepth 2 -type d
在我的命令提示符屏幕中,它再次为我提供了正确的答案,但不在bash文件中。
in my command prompt screen it gives me again correct answer, but not in bash file.
无论我搜索了什么,我都感到很困惑,没有找到任何其他替代mindepht标志的方法。
I am really confused whatever I searched I didn't find any alternative for mindepht flag.
推荐答案
它应该可以工作,但是如果由于某种原因它不能工作,则可以使用以下glob模式:
It should work but if for some reason it is not working then you can just use this glob pattern:
printf "%s\n" ./input/*/*/
./ input / * / * /
将匹配内所有2级深度目录输入
目录
这篇关于列出具有指定深度的文件夹的所有子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!