List readonly files

finderpermissionterminal

I need to list or show or query for the files in a folder (well, technically, on a USB drive, but I can navigate to it in Finder/Terminal) that are marked readonly.

All the Google-fu in the world just reveals solutions to change permissions but I don't need to do that.

My Dashcam marks videos/images readonly to save them when I press the button on it, but they're still in a folder with a few hundred MOV files, and I need a simple way to filter down to the ones I am looking for.

Best Answer

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