Shell – How to `find` all files and folders with 0** permissions

findosxpermissionsshell

I had a strange situation where I've found a number of files and folders that had 000 permissions set. This was easily repairable via:

sudo find . -perm 000 -type f -exec chmod 664 {} \; 
sudo find . -perm 000 -type d -exec chmod 775 {} \;

Unfortunately I suddenly realized the problem was a bit more complicated with some odd permissions such as 044 and some other strange settings. It turns out that these are strewn about and unpredictable.

Is there a way to search for permissions such as 0** or other such very limiting permission configurations?

Best Answer

I'd use something like this:

find . ! -perm -u=r ! -perm -u=w ! -perm -u=x -ls

Or if you prefer the octal notation:

find . ! -perm -400 ! -perm -200 ! -perm -100 -ls

Unfortunately, no idea, how to take it as one -perm option.

That syntax above is standard except for the -ls part (common but not POSIX) which you can replace with -exec ls -disl {} + on systems where find doesn't support -ls to get a similar output.

Related Question