49

I'm looking for a Linux command to go through all the directories on my server and find all files with 777 permission. The output would be a list of all those files with full path.

quack quixote
  • 42,186
  • 14
  • 105
  • 129

4 Answers4

65

Use find:

find / -type f -perm 0777
I say Reinstate Monica
  • 25,487
  • 19
  • 95
  • 131
jheddings
  • 781
  • 5
  • 5
17

And if you like to find all files without Permission 0777 then just enter a ! before the perm, e.g.

find / -type f ! -perm 0777

Kai
  • 171
  • 1
  • 2
9

You can also change the permissions or ownership of all those files resulting from the find execution using the -exec option to avoid change them manually.

Example: In a web server you could need to grant the group to write files:

find /var/www/html -type f -perm 0777 -exec chmod 775 {} \; -exec chgrp www {} \;
Jorge V.
  • 320
  • 3
  • 7
  • 1
    Be very very careful doing this - always worth using -exec ls first in order to see what the effect of your command will do. Find is super powerful and will often find things you didn't expect it to. – John Hunt Mar 24 '17 at 11:24
  • It's true. My command should be used once you know which files will result from the search. – Jorge V. Apr 05 '17 at 17:25
8

it's as easy as:

find / -perm 0777

if you only want to match files, use this instead:

find / -type f -perm 0777
knittl
  • 3,962
  • 2
  • 18
  • 18