The Stack Overflow podcast is back! Listen to an interview with our new CEO.
2 added 72 characters in body
source | link

If you would prefer not to invoke a subshell for every single file, this refinement of jlliagre's answer does it all with find predicates, as long as there are no ACLs to make it even more complicated. Correctly handling directories that are readable but not searchable is left as an exercise. If you haven't seen the #! thingy before, it means "don't try to copy all this onto the command line; instead, put it in a file, verbatim, chmod +x it, and invoke it as ./nameoffile <directory>."

#! /usr/xpg4/bin/sh

PATH=/usr/local/bin:/usr/xpg4/bin:/usr/bin:/bin
export PATH

me="-user $(id -u)"
my_groups="( -group $(id -G | sed 's/ / -o -group /g') )"

prune_me="( ( $me ! -perm -0400 ) -prune )"
prune_group="( ( ! $me $my_groups ! -perm -0040 ) -prune )"
prune_other="( ( ! $me ! $my_groups ! -perm -0004 ) -prune )"

find "$@" $prune_me -o $prune_group -o $prune_other -o -print

If you would prefer not to invoke a subshell for every single file, this refinement of jlliagre's answer does it all with find predicates, as long as there are no ACLs to make it even more complicated. Correctly handling directories that are readable but not searchable is left as an exercise. If you haven't seen the #! thingy before, it means "don't try to copy all this onto the command line; instead, put it in a file, verbatim, chmod +x it, and invoke it as ./nameoffile <directory>."

#! /usr/xpg4/bin/sh

me="-user $(id -u)"
my_groups="( -group $(id -G | sed 's/ / -o -group /g') )"

prune_me="( ( $me ! -perm -0400 ) -prune )"
prune_group="( ( ! $me $my_groups ! -perm -0040 ) -prune )"
prune_other="( ( ! $me ! $my_groups ! -perm -0004 ) -prune )"

find "$@" $prune_me -o $prune_group -o $prune_other -o -print

If you would prefer not to invoke a subshell for every single file, this refinement of jlliagre's answer does it all with find predicates, as long as there are no ACLs to make it even more complicated. Correctly handling directories that are readable but not searchable is left as an exercise. If you haven't seen the #! thingy before, it means "don't try to copy all this onto the command line; instead, put it in a file, verbatim, chmod +x it, and invoke it as ./nameoffile <directory>."

#! /usr/xpg4/bin/sh

PATH=/usr/local/bin:/usr/xpg4/bin:/usr/bin:/bin
export PATH

me="-user $(id -u)"
my_groups="( -group $(id -G | sed 's/ / -o -group /g') )"

prune_me="( ( $me ! -perm -0400 ) -prune )"
prune_group="( ( ! $me $my_groups ! -perm -0040 ) -prune )"
prune_other="( ( ! $me ! $my_groups ! -perm -0004 ) -prune )"

find "$@" $prune_me -o $prune_group -o $prune_other -o -print
1
source | link

If you would prefer not to invoke a subshell for every single file, this refinement of jlliagre's answer does it all with find predicates, as long as there are no ACLs to make it even more complicated. Correctly handling directories that are readable but not searchable is left as an exercise. If you haven't seen the #! thingy before, it means "don't try to copy all this onto the command line; instead, put it in a file, verbatim, chmod +x it, and invoke it as ./nameoffile <directory>."

#! /usr/xpg4/bin/sh

me="-user $(id -u)"
my_groups="( -group $(id -G | sed 's/ / -o -group /g') )"

prune_me="( ( $me ! -perm -0400 ) -prune )"
prune_group="( ( ! $me $my_groups ! -perm -0040 ) -prune )"
prune_other="( ( ! $me ! $my_groups ! -perm -0004 ) -prune )"

find "$@" $prune_me -o $prune_group -o $prune_other -o -print