How to find files on Linux where only root has read permission

14,475

Solution 1

find /home/mike/www/test -user root -perm +400 ! -perm +044 -print

-perm +400 matches files that have at least the owner-read mode set. -perm +044 matches files that have either group-read or other-read modes set, but ! inverts the test so these files are excluded from the result.

UPDATE: The man page for find(GNU findutils) says:

-perm +mode This is no longer supported (and has been deprecated since 2005). Use -perm /mode instead."

The updated command should be:

find /home/mike/www/test -user root -perm /400 ! -perm /044 -print

Solution 2

You need to use the find command to determine just which directories and files are only readable by root. Something like this might do what you want:

sudo find / -uid 0 -perm 600

This will generate a list of all files owned by UID 0 (root) with only read permissions for root. The list will be absolute pathnames.

You can redirect the output to a file, or pipe it to another program.

Do man find for a comprehensive list of options supported.

Share:
14,475

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I want to find files in some folder like /home/mike/www/test where only root has read permissions and not any other user.

    EDIT: I have the sudo and permission but I want to list all files where only root has read permission but not any group or public?

    • Peter Gluck
      Peter Gluck over 11 years
      Can you sudo to get root permissions?
    • Admin
      Admin over 11 years
      i have sudo and root permissions
    • joaquin
      joaquin over 11 years
      If a file has 0 permissions (or other weird settings like 333), then the owner cannot at the moment read those files (though the owner could change the permission so that they could read those files). Also, if a directory on the path leading to the file is not accessible (the x-bit) to the general world (e.g. the directory is owned by root with 700 permission), then ordinary files under that directory are not readable by others, regardless of who owns them or the permissions on the file. So, there are other possible interpretations for the question, but the selected answer is most plausible.
    • Admin
      Admin over 11 years
      how can i get those files who have special permissions
  • Admin
    Admin over 11 years
    i think u didn't understood my questions. I want to list all files in folders and under subfolders where only root has read permission but not any other user or group
  • Vijay Chavda
    Vijay Chavda about 6 years
    Says find: invalid mode ‘+400’
  • Barmar
    Barmar about 6 years
    @VijayChavda I can't reproduce that error. What version of find are you using?
  • Barmar
    Barmar about 6 years
    -perm 600 matches files with read and write, but not execute, permissions for the owner. It also excludes files where the group and other have write or execute permissions.
  • Barmar
    Barmar about 6 years
    Why has this answer been kept, since it's based on a misreading of the question?
  • Vijay Chavda
    Vijay Chavda about 6 years
    find (GNU findutils) 4.7.0-git
  • Barmar
    Barmar about 6 years
    I had no error with find 4.4.2 on Debian or BSD find on OS X. I don't know why you got that error. This syntax has been supported in find for decades.
  • Vijay Chavda
    Vijay Chavda about 6 years
    Even I'm not sure, but thanks for the help anyways.
  • Barmar
    Barmar about 6 years
    Do you get that error if you use -perm 400? This won't give the correct answer, it's just a test.