Linux find command permission denied

10,067

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

Share:
10,067

Related videos on Youtube

jianrui
Author by

jianrui

Updated on June 24, 2022

Comments

  • jianrui
    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 the find command as above to suppress the "Permission denied" information, but it still doesn't work.

  • jianrui
    jianrui over 7 years
    Thank you so much, in stead of redirect the stream, is it possible to bypass those folders that i don't have read permission ?
  • Vtik
    Vtik over 7 years
    Not sure, but, afaik, no !

Related