我想查找具有给定 inode 编号的文件。使用 find-inum
并不完全有用,因为它会列出来自每个文件系统/设备的具有 inode 编号的文件。如何将此搜索限制在特定设备/fs 中?
以下没有帮助 -
$ sudo find / -inum 2
/
/dev
/dev/shm
/dev/pts/ptmx
/sys/kernel/debug/acpi
/sys/fs
/sys/fs/cgroup
/sys/fs/cgroup/memory/cgroup.procs
/sys/fs/cgroup/pids/cgroup.procs
/sys/fs/cgroup/rdma/cgroup.procs
/sys/fs/cgroup/cpuset/cgroup.procs
/sys/fs/cgroup/devices/cgroup.procs
/sys/fs/cgroup/blkio/cgroup.procs
/sys/fs/cgroup/perf_event/cgroup.procs
/sys/fs/cgroup/freezer/cgroup.procs
/sys/fs/cgroup/hugetlb/cgroup.procs
/sys/fs/cgroup/cpu,cpuacct/cgroup.procs
/sys/fs/cgroup/net_cls,net_prio/cgroup.procs
/sys/fs/cgroup/systemd/cgroup.procs
/sys/fs/cgroup/unified/cgroup.procs
/run
/run/user/1000
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/run/user/125
find: ‘/run/user/125/gvfs’: Permission denied
/run/lock
/snap/gtk-common-themes/1506/meta/snap.yaml
/snap/snapd/8790/bin/fc-cache-v6
/snap/snapd/8542/bin/fc-cache-v6
/snap/tusk/29/LICENSES.chromium.html
/snap/gnome-3-34-1804/36/bin/bunzip2
/snap/gnome-3-34-1804/36/bin/bzcat
/snap/gnome-3-34-1804/36/bin/bzip2
/snap/snap-store/467/autostart/setup-autostart
/snap/core18/1885/bin
/snap/core18/1880/bin
/snap/jdownloader2/10/etc/X11
/snap/jdownloader2/12/etc/X11
/snap/core/9804/bin/bash
/proc/fs/nfsd/exports
/proc/sys/fs/binfmt_misc/status
下面确认上面列出的文件来自各种设备
/etc$ stat /dev/shm /dev /dev/pts/ptmx
File: /dev/shm
Size: 80 Blocks: 0 IO Block: 4096 directory
Device: 1ah/26d Inode: 2 Links: 2
Access: (1777/drwxrwxrwt) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-09-03 14:01:23.968171064 +0530
Modify: 2020-09-03 14:01:53.055049949 +0530
Change: 2020-09-03 14:01:53.055049949 +0530
Birth: -
File: /dev
Size: 4920 Blocks: 0 IO Block: 4096 directory
Device: 6h/6d Inode: 2 Links: 23
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-09-03 11:24:49.787963116 +0530
Modify: 2020-09-03 11:20:16.282767765 +0530
Change: 2020-09-03 11:20:16.282767765 +0530
Birth: -
File: /dev/pts/ptmx
Size: 0 Blocks: 0 IO Block: 1024 character special file
Device: 18h/24d Inode: 2 Links: 1 Device type: 5,2
Access: (0000/c---------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-09-03 10:18:19.587999997 +0530
Modify: 2020-09-03 10:18:19.587999997 +0530
Change: 2020-09-03 10:18:19.587999997 +0530
Birth: -
答案1
我倾向于使用sudo debugfs -R 'ncheck {inode}' /dev/{device} 2>/dev/null
它应该只列出该设备的文件。
由于您没有指定文件系统:这仅适用于 ext 并且我假设您使用了默认系统。
答案2
从man find
:
-mount Don't descend directories on other filesystems. An alternate name for -xdev, for compatibility with some other versions of find.