How to find files on Linux where only root has read permission
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.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
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 over 11 yearsCan you
sudo
to get root permissions? -
Admin over 11 yearsi have sudo and root permissions
-
joaquin over 11 yearsIf 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 over 11 yearshow can i get those files who have special permissions
-
-
Admin over 11 yearsi 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 about 6 yearsSays
find: invalid mode ‘+400’
-
Barmar about 6 years@VijayChavda I can't reproduce that error. What version of
find
are you using? -
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 about 6 yearsWhy has this answer been kept, since it's based on a misreading of the question?
-
Vijay Chavda about 6 yearsfind (GNU findutils) 4.7.0-git
-
Barmar about 6 yearsI had no error with
find 4.4.2
on Debian or BSDfind
on OS X. I don't know why you got that error. This syntax has been supported infind
for decades. -
Vijay Chavda about 6 yearsEven I'm not sure, but thanks for the help anyways.
-
Barmar about 6 yearsDo you get that error if you use
-perm 400
? This won't give the correct answer, it's just a test.