14

How can I determine all files and folders that given user can write to? The user is nobody. Some script in bash or python, perhaps? I'm using Ubuntu 11.04

don_crissti
  • 82,805
ren
  • 1,025
  • 3
  • 11
  • 16

1 Answers1

18
find / '(' -type f -o -type d ')' \
       '(' '(' -user  nobody -perm -u=w ')' -o \
           '(' -group nobody -perm -g=w ')' -o \
           '('               -perm -o=w ')' ')' -print

This will find all files and directories belonging to nobody that are writable by their owner, or that belong to the group nobody that are group writable, as well as all files or directories that are writable by anyone.

This would only take the primary group into account though.

Since generalizing this to take secondary groups (and ACLs etc.) into account would result in an even more unwieldy find expression, GNU find user could use

find / -type d -writable -print

This would report all directories writable by the current user. To use the same short syntax for finding directories writable by some other user, use sudo -u username find ..., i.e. change into that other user before running find (but see an answer to a related question for caveats and better alternatives).

Kusalananda
  • 333,661