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?

  • 1
    Can you sudo to get root permissions? Aug 31 '12 at 0:59
  • i have sudo and root permissions
    – user1596900
    Aug 31 '12 at 1:04
  • 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. Aug 31 '12 at 2:34
  • how can i get those files who have special permissions
    – user1596900
    Aug 31 '12 at 3:31
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
  • 1
    Says find: invalid mode ‘+400’ Mar 22 '18 at 20:11
  • @VijayChavda I can't reproduce that error. What version of find are you using?
    – Barmar
    Mar 22 '18 at 20:14
  • find (GNU findutils) 4.7.0-git Mar 23 '18 at 11:35
  • 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.
    – Barmar
    Mar 23 '18 at 11:38
  • Even I'm not sure, but thanks for the help anyways. Mar 23 '18 at 11:39

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.

  • -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
    Mar 22 '18 at 20:18

Try using the sudo command to elevate your permissions.

sudo ls /home/mike/www/test


sudo find /home/mike/www/test -name "foo" -print

If you cannot do that you will need to have a system administrator add your login to the /etc/sudoers file.

  • 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
    – user1596900
    Aug 31 '12 at 1:04
  • Ah, yes, I did misunderstand the question. Aug 31 '12 at 1:30
  • Why has this answer been kept, since it's based on a misreading of the question?
    – Barmar
    Mar 22 '18 at 20:24

Your Answer

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