List readonly files
Solution 1:
One way is to make use of the -w
option in bash to check if the file is writable or not.
Go into the directory you want to check your files, then enter:
for RO in $(find . -type f);do [ -r "$RO" ] && [ ! -w "$RO" ] && echo $RO;done
(credit to www.unix.com)
[EDIT]
To deal with spaces in file names, better to use the find -exec
way rather than looping into the find
:
find . -type f -exec [ -r {} ] \; -exec [ ! -w {} ] \; -exec echo {} \;
or
find . -type f -exec [ -r {} ] \; -exec [ ! -w {} ] \; -print
Solution 2:
find . -type f -perm +444 \! -perm +222
searches for all files (-type f
) which are readable (-perm +444
) but not writable (! +perm +222
).
If your mind boggles after reading up on -perm
in man find
you can also use the (significantly slower, especially on slow devices) option of processing the output of find
yourself:
find . -type f -print0 |
xargs -0 -n 1 sh -c '[ -r "$1" -a ! -w "$1" ] && echo "$1"' sh
This basically takes each file find
finds, and runs it through a small shells script to check permissions.
PS: Hey, I didn't say the second way is less mind-boggling :-)