Fun with find(1) (Re: Finding links)

Blair P. Houghton bph at buengc.BU.EDU
Fri Oct 20 10:12:03 AEST 1989


In article <598 at cogent.UUCP> doug at cogent.UUCP (Doug Perlich) writes:
>I ocasionally have problems working in large project groups when someone
>has a link (using ln) to a file.  I can't find the file that the link(s) are
>to.  (Different name, different directory).

Same inode.

    1.  Get the inode number of the file you know about:

	    ls -i filename.here

	which emits something like "5887 filename.here" where 5887
	is an example inum.

    2.  cd to the smallest directory (why start at / if you don't have
	to?) that you are sure includes the mystery filename, then

	    find . -inum 5887 -print

	and you should see all the filenames that link to that file.

If the link was symbolic rather than hard (i.e., made with
"ln -s file name" rather than "ln file name", which must be the
case if the link crosses a partition boundary, but is not
restricted to such cases) then it will have a different inum.
You can, however, do this:

    0.  cd to the smallest, etc., etc.

	    find . -type l -exec ls -l \{\} \; | grep filename.here

	and the name will pop out as in

-rw-r--r--  2 mrx   1 Oct 19 18:51 ./pathfoo/foo2 -> /pathhere/filename.here

and you can go ask mrx what he's doing linking foo2 to filename.here...

				--Blair
				  "I'm sure everyone else has a fave
				   method.  Let's slog through them
				   all, shall we? :-)"



More information about the Comp.unix.questions mailing list