How to exclude all “permission denied” messages from “find” in Solaris

findgrepsolaris

Hi previous questions on this topic contain answers for Linux but does not work for Solaris 10.

find . ! -readable -prune

Does not work in solaris since -readable is not POSIX.

What is the POSIX compliant command that exclude all “permission denied” messages from “find” in Solaris?

Correct answers: jlliagre and random832 gave correct answers.

Best Answer

Here is a POSIX way to prune any non readable directory with find :

find . \( -exec sh -c ' if [ ! -r "$1" ] ; then { exit 1 ; } ; else for i in "$1"/* ; do if [ -d "$i" -a ! -r "$i" ]; then exit 1; fi; done; fi ' sh {} \; -o -prune \) -a -print

Note that if this is a full Solaris installation, GNU grep is available in /usr/sfw/bin/ggrep.