How can I find all files I do not have write access to in specific folder?
Try
find . ! -writable
the command find
returns a list of files, -writable
filters only the ones you have write permission to, and the !
inverts the filter.
You can add -type f
if you want to ignore the directories and other 'special files'.
On non-Linux systems and systems without GNU find
, the following is likely to give the same output as find . -type f ! -writable
, it does however not take secondary groups into account.
myname=$( id -un )
mygroup=$( id -gn )
find . -type f '(' \
'(' -user "$myname" ! -perm -u=w ')' -o \
'(' ! -user "$myname" -group "$mygroup" ! -perm -g=w ')' -o \
'(' ! -user "$myname" ! -group "$mygroup" ! -perm -o=w ')' ')'
The four tests in order:
- Is it a regular file?
- Is it a file that I own but that I don't have write permissions to?
- Is it a file that I don't own, but that belongs to my group, and that I don't have group write permissions to?
- Is it a file that I don't own and that does not belong to my group, and that I don't have general ("other") write permissions to?
The benefit of this is that you may substitute in another user's name and group, which I don't think GNU find
's -writable
allows you to do.
The same command but with the logic written in AND form:
find . -type f \
! '(' -user "$myname" -perm -u=w ')' \
! '(' ! -user "$myname" -group "$mygroup" -perm -g=w ')' \
! '(' ! -user "$myname" ! -group "$mygroup" -perm -o=w ')'