问题
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 the find command as above to suppress the "Permission denied" information, but it still doesn't work.
回答1:
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.
回答2:
Something like this should work
find -type d ! -readable -prune -o -type f -name sources.list
回答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.)
回答4:
First you can check the ACL of folders with the help of
getfacl -R /foldername
if read permission is there to particular folder,then run;
find foldername -type f -name sources.list
else skip command
来源:https://stackoverflow.com/questions/37493764/linux-find-command-permission-denied