4

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

1 Answer 1

7

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
4
  • That will return everything except the 777 folders. Maybe I can find a way to prune if the parent is 777 ?
    – Slashterix
    Commented Feb 25, 2010 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. Commented Feb 25, 2010 at 20:31
  • I just suck at reading! You win! Thanks for the answer!
    – Slashterix
    Commented Feb 25, 2010 at 21:11
  • Completely understandable. It's some pretty counter-intuitive behavior from prune. Commented Feb 25, 2010 at 22:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .