VanLUG Email Archive

VanLUG Mailing List
Re: symbolic links..

New Message Reply About this list Date view Thread view Subject view Author view

Curt Sampson (cjs@cynic.net)
Sun, 20 Feb 2000 19:51:16 -0500 (EST)


On Sun, 20 Feb 2000, Tim Bray wrote:

> At 07:07 PM 2/20/00 -0500, Curt Sampson wrote:
> >Well, it's not going to be terribly easy, since there's no non-kludgy
> >way I know of to reliably get the target of a symlink in Unix.
>
> Er... really? What about something like
>
> find . -type l -exec ls -l {} \; | awk ' { print $9 " " $10 " " $11 }'

Sure. :-) And when you run it under Solaris, you get

    -> ./libXm.so.4
    -> ../dt/lib/libXm.so.3
    -> ../dt/lib/libXm.so.3
    -> ../dt/lib/libXm.so.4
    [etc.]

Well, you happen to be on a system where ls -l prints the group
name. What if someone else using your script isn't? :-)

Now this would be more reliable if you replaced `-exec ls -l {}
\;' with `-ls', but even so, I don't know that I'd trust all vendors
to implement the -ls option of find the same way; in particular,
it would not be unreasonable to want to print both the year and
the time, or give out a volume number along with the inode number.

Probably the most reliable would be to use my sed method, but first
check to see if the regexp / -> .* -> / is present in the line,
and drop the line (with a warning) if it is.

But more reliable yet would be just to have a C program that returns
the ultimate destination of a symlink so that the shell could call it.

(BTW, the -ls option on find is faster, as well as more convenient,
since you don't have to fork/exec for each file in the list you
find.)

cjs

-- 
Curt Sampson  <cjs@cynic.net>   917 532 4208   De gustibus, aut bene aut nihil.
The most widely ported operating system in the world: http://www.netbsd.org

--
This message came to you via the Vancouver Linux Users Group mailing list.
For unsubscription instructions do not email the list, but rather send mail
to <vanlug-request@gweep.bc.ca>.


New Message Reply About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b3 on Mon 21 Feb 2000 - 00:53:56