[comp.unix.wizards] How do you find the symbolic links to files.

chuck@trantor.harris-atd.com (Chuck Musciano) (11/17/90)

In article <4899@trantor.harris-atd.com>, tcurrey@x102a.ess.harris.com (currey tom 76327) writes:
> 
>    How do you find the # of and locations of all links to a file?

     This is an easy one.  You cannot.
     
     Well, sort of.  You cannot determine which hard links to a file exist
without examining all the directories in a given file system, looking for
the specific inode of the file in question.  Does anyone know of a tool to
do this?

     Symbolic links are tougher.  Since sym-links can span file systems and
NFS, you are not guaranteed to ever find all of them, only the ones in files
systems you have access to.  You need to use find to find all symbolic links,
and then examine the link to see if it points to the file in question.  This
can be tough, since some links are quite circuitous and not at all obvious.

     Easiest way: remove the file in question.  Wait for the phone to ring.
     
-- 

Chuck Musciano				ARPA  : chuck@trantor.harris-atd.com
Harris Corporation 			Usenet: ...!uunet!x102a!trantor!chuck
PO Box 37, MS 3A/1912			AT&T  : (407) 727-6131
Melbourne, FL 32902			FAX   : (407) 729-2537

A good newspaper is never good enough,
	but a lousy newspaper is a joy forever.		-- Garrison Keillor

tcurrey@x102a.harris-atd.com (currey tom 76327) (11/18/90)

In article <4900@trantor.harris-atd.com> chuck@trantor.harris-atd.com (Chuck Musciano) writes:
>In article <4899@trantor.harris-atd.com>, tcurrey@x102a.ess.harris.com (currey tom 76327) writes:
>> 
>>    How do you find the # of and locations of all links to a file?
>
>     This is an easy one.  You cannot.
>     
>
>     Symbolic links are tougher.  Since sym-links can span file systems and
>NFS, you are not guaranteed to ever find all of them, only the ones in files
>systems you have access to.  You need to use find to find all symbolic links,
>and then examine the link to see if it points to the file in question.  This
>can be tough, since some links are quite circuitous and not at all obvious.
>

  I already explained this to my customer,  I was just wonder if someone
had already figured out a 'find' command or graphical list of symbolic links.
I have designed for a program that would track each file in the system
separately and generate a table , but I don't have time to 
write a program to do this now.

   Example:  A is the object and has links B,C,D,E,F

     Output:    A--|
		   |
		   |-B--|
		   |    |-C
		   |    |-D
		   |-E
		   |-F

This only needs to usr a local mounted partition, not NFS.

The program I have designed would use major overhead for the system search,
but it is fairly easy to maintain a table of these links if you
start creating the tables first.

  To let some people know about the $ cost of packages on VMS that
to this is about $250,000+.


This might explain better I should have said in the first place.

			Tom Currey

rang@cs.wisc.edu (Anton Rang) (11/18/90)

[ I broadened distribution to comp.unix.programmer since c.u.w is gone. ]

In article <4901@trantor.harris-atd.com> tcurrey@x102a.harris-atd.com (currey tom 76327) writes:
>  I already explained this to my customer,  I was just wonder if someone
>had already figured out a 'find' command or graphical list of symbolic links.

  It's probably easiest to use the 'find -type l' trick that someone
already posted.  Slow, on a large file system, but it will get you all
of the symbolic links to an object.

>   Example:  A is the object and has links B,C,D,E,F
>
>     Output:    A--|
>		   |
>		   |-B--|
>		   |    |-C
>		   |    |-D
>		   |-E
>		   |-F

  Hmm.  I haven't quite figured this one out.  This picture makes it
look like B is a directory containing C, or something like that.  But
then they can't both be links to A...hmm.  Could you clarify a bit?

>The program I have designed would use major overhead for the system search,
>but it is fairly easy to maintain a table of these links if you
>start creating the tables first.

  If you need to do this for all of the files on the file system, you
could scan the file system, keeping track of all symbolic links as you
go ('find -type l' will do this), then run it through a program which
figures out which object (if any) they refer to.

  I don't think that keeping a table of the links would help if links
can be added and removed; you still need to scan the entire filesystem
to update your table.  (Of course, you could update it every night or
something like that, if that's reasonable.)

>  To let some people know about the $ cost of packages on VMS that
>to this is about $250,000+.

  Hmm.  Wait a minute.  First, VMS doesn't have symbolic links, so I'm
not quite sure what you mean by 'packages that do this.'  Second, I
don't know of any VMS software that costs that much, though I suppose
if you have enough machines and weird enough software....  (Hey, if
you want this for VMS, I'll write it up in a day for $50K.... :-)

>This might explain better I should have said in the first place.

  I'm still confused.  Do you mean something other than just
    'give me a list of all symbolic links which resolve to X'
  ?

	Anton
   
+---------------------------+------------------+-------------+
| Anton Rang (grad student) | rang@cs.wisc.edu | UW--Madison |
+---------------------------+------------------+-------------+