I'm trying to find all the web folders that are 777. But I only want a list of the top folders.

So if there is an img dir that has folders in it that are also 777 I don't want them returned.

Basically I'm looking for a way to have find stop descending after finding a folder that's 777.

find /var/www/vhosts/ -type d -perm 777

Gives me

/var/www/vhosts/example.com/httpdocs/img
/var/www/vhosts/example.com/httpdocs/img/gbl
/var/www/vhosts/example.com/httpdocs/img/ss

And all i want is the first one

/var/www/vhosts/example.com/httpdocs/img
link|improve this question

67% accept rate
feedback

1 Answer

up vote 4 down vote accepted

Use the -prune flag.

find /var/wwwhosts/ -type -d -perm 777 -prune should show exactly what you want.

Edit: Here's what this is doing for me, I believe this is what you wanted?

# ls -l
drwxrwxrwx 4 root root 4096 Feb 25 14:21 c

# ls -l c
drwxr-xr-x 2 root root 4096 Feb 25 14:21 1
drwxrwxrwx 2 root root 4096 Feb 25 14:21 2

# find . -perm 777 -prune
./c

# find . -perm 777 -prune -exec ls -ld {} \;
drwxrwxrwx 4 root root 4096 Feb 25 14:21 ./c
link|improve this answer
That will return everything except the 777 folders. Maybe I can find a way to prune if the parent is 777 ? – PHP-Steven Feb 25 '10 at 20:25
2  
Really? What OS/Bash version are you running on? This works perfectly for me. All the prune does is prevent recursing any further into the directory. It still prints the output. – Christopher Karel Feb 25 '10 at 20:31
I just suck at reading! You win! Thanks for the answer! – PHP-Steven Feb 25 '10 at 21:11
Completely understandable. It's some pretty counter-intuitive behavior from prune. – Christopher Karel Feb 25 '10 at 22:26
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.