Ubuntu – How to find world writable files and folders and set the sticky bit

command linefindpermissions

I want to do the following:

  1. Need to find all world writable files and folders from / root.
  2. If found, I need to check whether the sticky bit is set or not.
  3. If the sticky bit is not set, then set it.

Can we come up with a command line solution for this type of problem?

Best Answer

You can do this using find's -perm -mode format. From man find:

-perm -mode

All of the permission bits mode are set for the file. Symbolic modes are accepted in this form, and this is usually the way in which would want to use them. You must specify u',g' or `o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples.

So, to find all files that are world writeable, irrespective of what other permissions they have, you can do:

find / -perm -o+w 

To set the sticky bit, use -exec:

find . -perm -o+w -exec chmod +t {} + 
Related Question