Finding links
Keith Gabryelski
ag at cbmvax.UUCP
Thu Oct 19 22:15:58 AEST 1989
In article <598 at cogent.UUCP> SomeOne writes:
>I want to type "findthelinktothefile foobar"
>and it will respond "/path1/path2/.../abc/foobee" and any other names
>linked to the file.
All files are represented by something called an inode on disk. When
you reference a file by its text name (ie /usr/myhome/foo) the kernel
actually interprets that into an number corresponding to an entry in a
table that is kept on disk. This table has all the interesting
information about the file (its size, timestamps, where it is on the
disk and its 'link count').
The link count is the number of directory entries that point to this
inode. There is a separate inode table for each partition, so file
links cannot span filesystems [*] since this would require unique
inode numbers for all files on all mounted partitions (filesystems).
Use 'ls -i FILENAME' to find the inode number of the file in question.
Then use 'find PATHNAME -inum INODE -print' to find all files with
inode INODE and start searching from the PATHNAME directory. PATHNAME
should be the mount point directory of whatever filesystem FILENAME
was on (You can use 'df filename' on some systems to find this out, or
you may have to use 'df' and figure it out yourself).
Note: PATHNAME could also be '/' but then find(1) will show all files
with the same inode number even if the are on separate partitions
(which isn't what you want, since these files are not the same).
So, for example:
# I want to find all the file names for the inode corresponding to
# the file $HOME/aen.c.
#
$ ls -i $HOME/aen.c
38 /z/unix/ag/aen.c
#
# 38 is the inode number for /z/unix/ag/aen.c. Lets find the
# mount point directory.
#
$ pwd
$ /z/unix/ag
$ df .
Filesystem Total kbytes kbytes %
node kbytes used free used Mounted on
/dev/hp2c 113863 86316 16161 84% /z
#
# So, we should start at /z since anything before it is not on the
# partition we are interested in (thus could not have a link
# coressponding to the file we are look for) [**]
#
$ find /z -inum 38 -print
/z/unix/ag/c/foo.c
/z/unix/ag/tmp/FOOBAR
/z/unix/ag/emd/amstr.c
/z/unix/ag/aen.c
#
# We are done.
#
Home this helps,
Pax, Keith
[*] Files can have links to files on other partitions, but this is
done through a mechanism call 'soft links' that may not exist on your
system (they exist on berkeley derived or sufficiently mutated SYSV
systems). You can tell if a file is a soft link by doing an 'ls -l',
as:
$ ls -l /tmp/Aen.c
lrwxr-xr-x 1 ag 5 Oct 19 08:04 /tmp/Aen.c -> /z/unix/ag/aen.c
#
# Soft links are done in a entirely different way then 'hard links' so
# inode links don't come into play.
#
[**] It is possible that a filesystem could have been mounted on /z
somewhere. This may have caused problems because of inode clashes.
--
"It took no computation to dance to the rock 'n roll station" -- VU
ag at cbmvax.commodore.com Keith M. Gabryelski ...!uunet!cbmvax!ag
More information about the Comp.unix.questions
mailing list