使用“find”循环目录。-深度 1 -类型 d`

war*_*rdz 1 bash find for

我已获得一个要运行的脚本,但在调用find . -depth 1 -type d. 它会产生以下错误,

find: paths must precede expression: `1'
Run Code Online (Sandbox Code Playgroud)

这是失败的那一行,

for dir in `find . -depth 1 -type d`
do
    ....
Run Code Online (Sandbox Code Playgroud)

我尝试了很多事情但没有成功。我真的不明白为什么它会给出错误,因为至少在我看来,路径确实在“1”之前。

Bib*_*Bib 5

该-depth开关不带参数,但是-maxdepth does,所以:

for dir in `find . -depth -maxdepth 1 -type d`
do
    ....
Run Code Online (Sandbox Code Playgroud)

应该管用。

-depth手册页中的参数意味着首先处理目录内容。