[boulder.pm] Finding a symbolic link target

Justin Crawford Justin.Crawford at cusys.edu
Mon Sep 24 10:33:51 CDT 2001


Wulp, here's my quickie way of doing UNIX fs operations...

#!/usr/local/bin/perl

die "Usage: $0 filename\n" unless (@ARGV);

foreach my $file (@ARGV) {
  die "$file is not a valid filename\n" unless (-e $file && ! -d $file);
  chomp (my $ls = `ls -l $file`);
  if (-l $file && $ls =~ m/->\s+(.+)$/) {
    print "$file is a link to $1\n";
  }
  else {
    print "$file is not a link\n";
  }
}

-----Original Message-----
From: Myke Komarnitsky [mailto:myke at komar.org]
Sent: Friday, September 21, 2001 7:32 PM
To: boulder-pm-list at happyfunball.pm.org
Subject: [boulder.pm] Finding a symbolic link target


I'm hoping you gurus out there can help me.

These are my two files,
lrwxrwxrwx    1 myke     nobody         40 Sep 20 11:15 search.words -> 
search.real.words
-rwxrwxrwx    1 myke     nobody       5000 Sep 20 11:15 search.real.words

and here's the important part of the perl script:
foreach $line (@ARGV) {
         if (-l $line) {
		print "$line is a symbolic link...";
	}
}

the trouble is, I really need to know what the TARGET of that symbolic link 
is.  Does anybody know how I can grab it?

thanks in advance,
Myke

Michael Komarnitsky      Komar Consulting Group
303.818.3718             http://consulting.komar.org
http://climbingboulder.com
-



More information about the Boulder-pm mailing list