为什么发现命令对已排除的路径给出“权限被拒绝”错误?

为什么发现命令对已排除的路径给出“权限被拒绝”错误?

如果我运行(使用 sudo)

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

它可以正常工作,没有任何问题。

但是,如果我在没有 sudo 的情况下运行相同的命令,我会在控制台中收到一些错误。搜索结果log.txt是正确的(没有问题)。但我不明白错误消息。

% 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

为什么它说find: ‘/timeshift/snapshots/....’: Permission denied即使我! -path '/timeshift/*'在我的 find 命令中使用了。根据我的常识,find 命令不需要关心已从搜索中排除的目录的权限。

那么,到底发生了什么以及如何在不使用 sudo 的情况下消除这些错误消息。我的意思是,find 命令中是否有任何位置参数表示“先排除然后搜索”或类似的内容。

答案1

使用-path,您可以测试当前路径名是否与模式匹配,然后排除它或继续处理它。它不会停止find进入子目录。

要修剪搜索树(从搜索中删除目录),请使用-prune.

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

这会修剪与两个测试之一匹配的路径-path,并输出与常规文件对应的所有其他路径名。不会输入修剪过的路径find,因此在上面的命令中, 下的任何内容/home/blueray/timeshift什至不会被 考虑find

相关内容