find . -type f | xargs ls -l | grep -v rw-r--r--
"find all files in current directory, pass to "ls -l" to list their detail, and scan the output of ls
for all the lines not (the -v option to grep negates the match) containing "rw-r--r--" and for directories:
find . -type d | xargs ls -l | grep -v drw-r--r--
If you want to scan another directory replace "." with it, such as:
find /path/to/directory -type f | xargs ls -l | grep -v rw-r--r--
and if some of the file/directory names might contain spaces use the "use 0-delimited strings" options in find and xargs like so to avoid errors:
find . -type f -print0 | xargs -0 ls -l | grep -v rw-r--r--
Also, you can remove the -v
option from grep to find files/directories that do match, if you want to list these as a sanity check.
Using find
will scan subdirectories too by default. To scan just one directory and not its children, you could just pipe the output of ls -l
through grep
instead of using find
and xargs
.
When you do run chmod
remember that you can specify the -v
option so it will list what it does and doesn't change as it performs the operation - this can be useful for reassuring yourself that you've given the right command.