3

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
jianrui
  • 151
  • 1
  • 1
  • 9
  • 1
    Possible duplicate of [How can I exclude all "permission denied" messages from "find"?](http://stackoverflow.com/questions/762348/how-can-i-exclude-all-permission-denied-messages-from-find) – Jonathan Leffler May 28 '16 at 00:05

4 Answers4

6

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.

Vtik
  • 3,073
  • 2
  • 23
  • 38
5

Something like this should work

find -type d ! -readable -prune -o -type f -name sources.list
Reinstate Monica Please
  • 11,123
  • 3
  • 27
  • 48
1

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.)

Decano
  • 11
  • 1
-1

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

sumitya
  • 2,631
  • 1
  • 19
  • 32