4

If I run (with sudo)

sudo find / -xdev -type f ! -path '/home/blueray/*' ! -path '/timeshift/*' > log.txt

It works properly without any issues.

However, if I run the same command without sudo , I get some error in console. The search result in log.txt is proper (no issue with that). But I am not understanding the error messages.

% find / -xdev -type f ! -path '/home/blueray/*' ! -path '/timeshift/*' > log.txt
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/etc/polkit-1/localauthority’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/etc/ssl/private’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/etc/cups/ssl’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/log/private’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/log/speech-dispatcher’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/spool/rsyslog’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/spool/cups’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/spool/cron/crontabs’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/apt/lists/partial’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/colord/.cache’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/AccountsService/users’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/bluetooth/5C:F3:70:93:BD:85’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/lightdm-data/lightdm’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/polkit-1’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/udisks2’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/NetworkManager’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/private’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/lightdm’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/lib/tor’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/cache/private’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/cache/apparmor/26b63962.0’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/cache/lightdm/dmrc’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/cache/cups’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/cache/ldconfig’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-tor@default.service-frAbZe’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-systemd-logind.service-EWXwaj’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-ModemManager.service-0wY2Hh’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-colord.service-HLWVQf’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-upower.service-ecD4ii’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-systemd-resolved.service-Qxjpij’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/var/tmp/systemd-private-84c1e6e852b747ea9d34d17ca664b32b-systemd-timesyncd.service-Kf61Zi’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/root’: Permission denied
find: ‘/timeshift/snapshots/2022-01-09_22-00-46/localhost/boot/efi’: Permission denied
find: ‘/etc/libvirt/secrets’: Permission denied
find: ‘/etc/polkit-1/localauthority’: Permission denied
find: ‘/etc/ssl/private’: Permission denied
find: ‘/etc/cups/ssl’: Permission denied
find: ‘/var/log/private’: Permission denied
find: ‘/var/log/speech-dispatcher’: Permission denied
find: ‘/var/spool/rsyslog’: Permission denied
find: ‘/var/spool/cups’: Permission denied
find: ‘/var/spool/cron/crontabs’: Permission denied
find: ‘/var/lib/apt/lists/partial’: Permission denied
find: ‘/var/lib/colord/.cache’: Permission denied
find: ‘/var/lib/AccountsService/users’: Permission denied
find: ‘/var/lib/portables’: Permission denied
find: ‘/var/lib/libvirt/qemu’: Permission denied
find: ‘/var/lib/machines’: Permission denied
find: ‘/var/lib/bluetooth/5C:F3:70:93:BD:85’: Permission denied
find: ‘/var/lib/lightdm-data/lightdm’: Permission denied
find: ‘/var/lib/polkit-1’: Permission denied
find: ‘/var/lib/udisks2’: Permission denied
find: ‘/var/lib/NetworkManager’: Permission denied
find: ‘/var/lib/private’: Permission denied
find: ‘/var/lib/lightdm’: Permission denied
find: ‘/var/lib/tor’: Permission denied
find: ‘/var/lib/fwupd/gnupg’: Permission denied
find: ‘/var/cache/apt/archives/partial’: Permission denied
find: ‘/var/cache/private’: Permission denied
find: ‘/var/cache/apparmor/26b63962.0’: Permission denied
find: ‘/var/cache/lightdm/dmrc’: Permission denied
find: ‘/var/cache/cups’: Permission denied
find: ‘/var/cache/ldconfig’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-ModemManager.service-G72K7i’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-colord.service-2B8Ofg’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-tor@default.service-TaP1xi’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-systemd-logind.service-rnYjPi’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-systemd-timesyncd.service-U7G6Lf’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-systemd-resolved.service-ABf5Xe’: Permission denied
find: ‘/var/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-upower.service-WW9yYi’: Permission denied
find: ‘/root’: Permission denied
find: ‘/lost+found’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-upower.service-F7Rtjf’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-tor@default.service-nYCXFi’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-colord.service-qGi0sf’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-systemd-logind.service-FhyyUh’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-systemd-resolved.service-luOB7f’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-ModemManager.service-d1MZ7g’: Permission denied
find: ‘/tmp/systemd-private-c9d7a83d6f844d998e8423d94d48ce3f-systemd-timesyncd.service-79KkRe’: Permission denied

Why is it saying find: ‘/timeshift/snapshots/....’: Permission denied even though I have used ! -path '/timeshift/*' in my find command. As per my common sense, the find command need not to bother about the permission of a directory which has been excluded from search.

So, what is really going on and how to get rid of these error messages without using sudo. I mean, is there any positional parameter in find command which says "first exclude then search" or something like that.

1

1 Answer 1

10

With -path, you test whether the current pathname matches a pattern, and then exclude it or continue processing it. It does not stop find from entering sub-directories.

To prune the search tree (remove directories from the search), use -prune.

find / -xdev \
    \( -path '/home/blueray' -o -path '/timeshift' \) -prune -o \
    -type f -print

This prunes the paths matching either of the two -path tests, and outputs all other pathnames corresponding to regular files. A pruned path will not be entered by find, so in the command above, nothing under /home/blueray or /timeshift will even be considered by find.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .