Linux find command permission denied
Solution 1
Something like this should work
find -type d ! -readable -prune -o -type f -name sources.list
Solution 2
try the following
find -type f -name sources.list 2>/dev/null
This will redirect stderr
output stream, which is used to report all errors, including the "Access denied" one, to null device.
Solution 3
The following worked for me:
find / -mount -readable -name "<whatever>" -print
Here I only wanted to search the root file system, and not descent into any of the mounted file systems. Hence -mount.
The problem files that were throwing errors were not readable (yielding "permission denied"). Hence -readable.
The rest is obvious.
(Note: In Ubuntu 16.04 the files in /var/lib/lxcfs are not readable, even for root. The above solved the problem for me.)
Related videos on Youtube
jianrui
Updated on June 24, 2022Comments
-
jianrui over 1 year
I want to filter out the unnecessary information "Permission denied". these are outputs from command "
find -type f -name sources.list
"find: './run/lxcfs': Permission denied find: './run/sudo': Permission denied find: './run/lvm': Permission denied find: './tmp/systemd-private-99eef94819d84080adc7df3e60efee5b-systemd-timesyncd.service-HE48k9': Permission denied find: './lost+found': Permission denied find: './dev/vboxusb': Permission denied find: './root': Permission denied ./etc/apt/sources.list find: './etc/sudoers.d': Permission denied
I tried to use "
! -readable -prune
" in conjunction with thefind
command as above to suppress the "Permission denied" information, but it still doesn't work.-
Jonathan LefflerPossible duplicate of How can I exclude all "permission denied" messages from "find"?
-
-
jianrui over 7 yearsThank you so much, in stead of redirect the stream, is it possible to bypass those folders that i don't have read permission ?
-
Vtik over 7 yearsNot sure, but, afaik, no !