How can I find all files I can not write to?

Would be good if it takes standard permissions and acls into account.

Is there an "easy" way or do I have to parse the permissions myself?

  • should it consider only files owned by the current user(you)? – RomanPerekhrest Feb 19 '18 at 15:16
  • Should consider all files I cannot write to – Alex Feb 19 '18 at 15:19
  • it's too simple find . -type f ! -writable – RomanPerekhrest Feb 19 '18 at 15:20
  • Roman's answer works. It wouldn't contain files of which Alex is the owner because that would mean that he can write to them. – Nasir Riley Feb 19 '18 at 15:27


find . ! -writable

the command file lists the files, -writable filters only the one you have write permission and the ! inverts the filter

You can add -type f if you want to ignore the directories and other 'special files'

| improve this answer | |
  • 2
    And add -user <username/userid> if you want to restrict this to a specific user. – Raman Sailopal Feb 19 '18 at 15:19
  • Note that it misses the ones that are in directories you don't have search or read access to. – Stéphane Chazelas Feb 19 '18 at 16:52
  • It should also be noted that if you own the file, you can always give yourself write permission to it. And if you have write permission to the directory the file is in, you can always replace the file with another one. – Stéphane Chazelas Feb 19 '18 at 16:52
  • is ! ... a substitution? – cat Feb 20 '18 at 0:15
  • 1
    @cat It's find syntax, but the man page notes "This character will also usually need protection from interpretation by the shell." If you're using GNU find, you can also use -not. – wjandrea Feb 20 '18 at 2:41

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:

  1. Is it a regular file?
  2. Is it a file that I own but that I don't have write permissions to?
  3. 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?
  4. 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 ')'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.