[comp.unix.questions] How to find directory name at end of symbolic links

maine@unet.UUCP (Dennis J. W. Maine) (03/09/89)

I am using SunOs 3.5 and want to know how to find out the directory
name at the end of a series of symbolic links.  The -L option for
ls does not seem to work with -l option.  For example, if /dir1/a is
linked to /dir2/a is linked to /dir3/a then if I enter ls -L /dir1/a
I want to know that dir3 contains the actual file a. Entering successive
ls -l commands for dir1, dir2 and dir3 is a drag.

Any ideas?

adTHANKSvance,
	djwm
-- 
Dennis J. W. Maine
{oliveb!ames!tymix!sunncal!amdahl!pacbell!}unet!maine
[These are my personal opinions: fill in your favorite disclaimer]

gandalf@csli.STANFORD.EDU (Juergen Wagner) (03/10/89)

In article <304@unet.UUCP> maine@unet.PacBell.COM (Dennis J. W. Maine) groovily writes:
>I am using SunOs 3.5 and want to know how to find out the directory
>name at the end of a series of symbolic links.

You have to use the readlink system call. On csli.stanford.edu I have put a
program readlink (anon ftp from pub/Gandalf) which does what you want.

-- 
Juergen Wagner		   			gandalf@csli.stanford.edu
						 wagner@arisia.xerox.com

white@white.cs.unc.edu (Brian T. White) (03/10/89)

> I am using SunOs 3.5 and want to know how to find out the directory
> name at the end of a series of symbolic links.  
>
> Any ideas?

Try this:

#! /bin/csh -f

foreach file ($argv[1-])
        echo ""
        if (! -e $file) then
                echo $file does not exist
                continue
        endif
        echo "$file"
        set islink
        while ($?islink)
                set listing=`ls -ld $file`
                echo $listing | grep -s ^lrwx
                if ($status) then
                        unset islink
                else
                        set file=`echo $listing | awk '{print $NF}'`
                        echo " -> $file"
                endif
        end
end
echo ""

arnold@mathcs.emory.edu (Arnold D. Robbins {EUCC}) (03/11/89)

In article <304@unet.UUCP> maine@unet.PacBell.COM (Dennis J. W. Maine) writes:
>I am using SunOs 3.5 and want to know how to find out the directory
>name at the end of a series of symbolic links.

Easy enough:

	$ (cd /dir1/a ; /bin/pwd)
-- 
Unix is a Registered   | Arnold Robbins -- Emory University Computing Center
Bell of AT&T Trademark | DOMAIN: arnold@unix.cc.emory.edu		
Laboratories.          | UUCP: gatech!emory!arnold	PHONE:	+1 404 727-7636
        -- Donn Seeley | BITNET: arnold@emoryu1		FAX:	+1 404 727-2599

barnett@crdgw1.crd.ge.com (Bruce Barnett) (03/13/89)

In article <3803@emory.mathcs.emory.edu>, arnold@mathcs (Arnold D. Robbins {EUCC}) writes:
>In article <304@unet.UUCP> maine@unet.PacBell.COM (Dennis J. W. Maine) writes:
>Easy enough:
>
>	$ (cd /dir1/a ; /bin/pwd)

You may wish to do a 'set hardpaths' first.

--
	Bruce G. Barnett 	barnett@ge-crd.ARPA, barnett@steinmetz.ge.com
				uunet!steinmetz!barnett

pvo1478@neptune.uucp (Paul O'Neill) (03/14/89)

In article <304@unet.UUCP> maine@unet.PacBell.COM (Dennis J. W. Maine) writes:
>I am using SunOs 3.5 and want to know how to find out the directory
>name at the end of a series of symbolic links.  ...............

How about:

#!/bin/csh -f
set hardpaths
cd $argv[1]
echo $cwd

Or set hardpaths in your working shell to always see where you really are.


Paul O'Neill                 pvo@oce.orst.edu
Coastal Imaging Lab
OSU--Oceanography
Corvallis, OR  97331         503-754-3251

barnett@crdgw1.crd.ge.com (Bruce Barnett) (03/14/89)

In article <27@crdgw1.crd.ge.com>, I wrote:
>>	$ (cd /dir1/a ; /bin/pwd)
>You may wish to do a 'set hardpaths' first.

Oops! Sorry about that. you only need to set hardpaths if you use $cwd in csh.
pwd always gives you the 'hardpath'

--
	Bruce G. Barnett 	barnett@ge-crd.ARPA, barnett@steinmetz.ge.com
				uunet!steinmetz!barnett