Controlling depth with find

I have the following script:

Now they have added on a new requirement, they only want to go to a certain depth in the directories returned. How do I code it to only go say 3 directories deeper than $DIRECTORY?

Some versions of find have a -maxdepth option. In the absence of that, something like find | egrep -v '/.*/.*/.*/' | xargs du -ks is probably the way to go.

There is no maxdepth avilable in my version of find.

Hoiw do I use that code you gave me. When I tried to use it - I got 6786785 .

I put it in like this:

What am I doing wrong?

/usr/bin/ssh -q $ID@$SERVER "find $DIRECTORY -type d -exec du -ks {} \; | awk -F/ 'NF <= 3'" >> $MDIR/bldtuout.txt 2>> $MDIR/bldterr.txt

I am not receiving anything when I try to use that code. The output file is blank.

I have no problem with that command on AIX...what system are you on.

I am on solaris

Can you show what's the output of this ssh command on your system.

/usr/bin/ssh -q $ID@$SERVER "find $DIRECTORY -type d -exec du -ks {} \; | awk -F/ 'NF <= 3'"

It ran for a couple of seconds and returned nothing.

Argh! on Solaris use nawk instead of awk.

I ran this:

and it still ran for a couple of seconds, but returned nothing.

Let's see if this fixes it or wait for somebody else to help with this. Since you want to go down to no more than 3 levels below $DIRECTORY the command needs to be.

/usr/bin/ssh -q $ID@$SERVER "find $DIRECTORY -type d -exec du -ks {} \;" | nawk -F"/" 'NF <= 5'

You forgot the xargs in the code I posted