Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!wuarchive!udel!haven!purdue!spaf From: spaf@cs.purdue.EDU (Gene Spafford) Newsgroups: comp.unix.internals Subject: Re: How do you find the symbolic links to files. Message-ID: <12575@medusa.cs.purdue.edu> Date: 27 Nov 90 06:09:20 GMT References: <25110@adm.brl.mil> Sender: news@cs.purdue.EDU Reply-To: spaf@cs.purdue.edu (Gene Spafford) Organization: Department of Computer Science, Purdue University Lines: 48 Okay, the question is, how do you find all links to a file? Hard links are easy. Barry & I have shown two ways -- using find and ncheck -- to do it. Hard links, by their nature, must always reside in the same disk partition as the file system entry they describe (doesn't have to be a file -- links can be to directories, FIFOs, devices, etc...anything describeable by an i-node). Anyhow, the question was then posed, as posed before, how to find all the symbolic links. The simple answer given earlier is "You can't." I'll give the same answer, but also try to explain it. A symbolic link contains a pathname to the object it describes. Therefore, the symbolic link can exist on another disk partition and still be valid. That means that there could be a link to your file but it is not "active" right now. For instance, if the partition on which the link exists is not currently mounted, the link isn't there, but as soon as the partition is mounted it is a link to your file. Or consider this. If I mount a partition on /mnt, and create a symbolic link to the ../etc/passwd file, that works until I unmount and remount the file system on /usr/tmp in which case the link no longer works. Other examples come to mind, but the same thing happens. There could be lots of links to your file, but they currently aren't available. Now let's refine the problem some and ask how to find all currently available symbolic links (mounted in proper places, etc) that point to a specific file system entry. That's not simple, but it is possible-- however, I don't know of a way to do this with standard commands. You need to compare major dev, minor dev, i-node triples to make an exact determination, and I can't think of a standard utility that reports the device numbers. You can't just compare contents, because it is possible that a copy of a file could be made on another parition and end up with the same i-node number. Unlikely, but possible. The way to do it is to write a program that stats your object, and gets the device numbers and i-node number. Then scan the file system (using find, for instance) looking for symbolic links. For each one found, fetch the device numbers and compare against your saved trio. Voila. Not simple, but it will work. -- Gene Spafford NSF/Purdue/U of Florida Software Engineering Research Center, Dept. of Computer Sciences, Purdue University, W. Lafayette IN 47907-2004 Internet: spaf@cs.purdue.edu uucp: ...!{decwrl,gatech,ucbvax}!purdue!spaf