Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!world!bzs From: bzs@world.std.com (Barry Shein) Newsgroups: comp.unix.internals Subject: Re: How do you find the symbolic links to files. Message-ID: Date: 27 Nov 90 17:07:56 GMT References: <25110@adm.brl.mil> Sender: bzs@world.std.com (Barry Shein) Organization: The World Lines: 50 In-Reply-To: mchinni@pica.army.mil's message of 26 Nov 90 21:46:41 GMT From: mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) >If so, how would you find all symbolic links to the file ? In general, it's very difficult. Consider that valid symlinks can point across NFS mounts. I have just created the following: % ln -s /pica.army.mil/root/etc/termcap ./termcap That's a perfectly valid symlink from my machine to your termcap file. I can't resolve it right now because I can't NFS mount your root directory, but it's still a symlink to your termcap file, no? How would you find it? In fact, to be more realistic, NFS mounts are not even commutative (some workstation at your site can mount and point thru a file system on your system, but you can't necessarily see that valid symlink.) But, if we narrow the question to "how can I find all the symlinks I can find?" the find command can locate every symlink (-type l) and they can be resolved and their i-node numbers tested for equality with a target with an only slightly convoluted shell command (or trivially by writing a 20 line C-program which can be -exec'd by find with the path in question and the inode number desired.) % find /mount-point -type l -a -exec testinode '{}' #inum ';' where testinode is just something like: #include #include #include main(argc,argv) int argc; char **argv; { struct stat st; if(!stat(argv[1],&st) && (st.st_ino == atoi(argv[2]))) printf("%s\n",argv[1]); exit(0); } (you could add argv checks) -- -Barry Shein Software Tool & Die | {xylogics,uunet}!world!bzs | bzs@world.std.com Purveyors to the Trade | Voice: 617-739-0202 | Login: 617-739-WRLD