u='-user "$USER"'
g='\('$(IFS=\ ;printf " -group %d " $(id -G))'\)'
eval "find / $u \( -perm -u=rx -o -prune \) -o \
$g \( -perm -g=rx -o -prune \) -o \
-perm -o=rx -o -prune" | wc -l
That works. Because file permissions are always evaluated at the most specific level possible, you don't have to -o
r too much. If a file is owned by someuser and is readable by others and groups but not by the owner then someuser still cannot read it. And so you just need to start at the most specific permission match and work your way down from there, -pruning
all the while.
find: `/proc/3379/task/3379/fd/5': No such file or directory
find: `/proc/3379/task/3379/fd/5': No such file or directory
find: `/proc/3379/task/3379/fd/5': No such file or directory
find: `/proc/3379/task/3379/fd/5': No such file or directory
find: `/proc/3379/task/3379/fdinfo/5': No such file or directory
find: `/proc/3379/task/3379/fdinfo/5': No such file or directory
find: `/proc/3379/task/3379/fdinfo/5': No such file or directory
find: `/proc/3379/task/3379/fdinfo/5': No such file or directory
find: `/proc/3379/fd/5': No such file or directory
find: `/proc/3379/fd/5': No such file or directory
find: `/proc/3379/fd/5': No such file or directory
find: `/proc/3379/fd/5': No such file or directory
find: `/proc/3379/fdinfo/5': No such file or directory
find: `/proc/3379/fdinfo/5': No such file or directory
find: `/proc/3379/fdinfo/5': No such file or directory
find: `/proc/3379/fdinfo/5': No such file or directory
327652
As you can see, at no point is there a permissions issue, just a few occasionally race issues to do with /proc
- which is unavoidable when spawning files to read files.
Permission denied
error) but it allows you to descend through the directory and access items within it if you already know the file or path name beneath it (and have the appropriate permissions there), so it can provide a useful layer of security.