Thursday, October 6, 2022

[SOLVED] Looping over dirs using `find . -depth 1 -type d`

Issue

I've been given a script to run, but it produces an error when calling find . -depth 1 -type d. It produces the following error,

find: paths must precede expression: `1'

This is the line in which it fails,

for dir in `find . -depth 1 -type d`
do
    ....

I have tried quite a few things without success. And I don't really see why it gives the error since it seems to me at least, that the paths does indeed precede the "1".


Solution

Not all find implementations support -depth 1. A portable alternative would be:

find . ! -name . -type d -prune


Answered By - oguz ismail
Answer Checked By - Marie Seifert (WPSolving Admin)