0

I want to find the files with a given inode number. Using find with -inum is not entirely helpfull as its listing files with the inode number from every file system/device. How to confine this search to a particular device/fs?

Below is not helpfull -

$ 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 

Below confirms that above listed files are from various devices

/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: -
5
  • If you know what filesystem you want to search on, why don't you just use that as the start search path and use the -xdev primary?
    – Kusalananda
    Sep 3, 2020 at 9:17
  • @Kusalananda, cool - how to prefix, can you give the syntax
    – samshers
    Sep 3, 2020 at 11:59
  • you mean - find /dev -xdev ... or find /proc -xdev ...
    – samshers
    Sep 3, 2020 at 12:01
  • Exactly, and this is what Stephen is suggesting in their answer too.
    – Kusalananda
    Sep 3, 2020 at 13:30
  • There is also -samefile in GNU find Sep 13, 2020 at 22:13

1 Answer 1

3

Use -xdev (as shown in previous answers to your questions involving find):

find / -xdev -inum 2

Replace / with whatever mount point you’re interested in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.