Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Symbolic Links

by Anonymous Monk
on Aug 02, 2001 at 20:33 UTC ( [id://101705]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a script that finds directories that are symbolically linked to accounts and then displays where that symbolic link is.
Is there a function of perl that displays where directories are linked?

I just want to avoid using something like:

open (SYMDIR, "cd /some/directory | pwd |");
print SYMDIR;

Well, actually there are other ways than that... But anyway, any help would be appreciated =)

Replies are listed 'Best First'.
Re: Symbolic Links
by grinder (Bishop) on Aug 02, 2001 at 20:39 UTC
    You want to investigate the readlink function.

     my $dir = readlink( '/some/directory' );

    If you have symbolic links pointing to other symbolic links you will have to walk down the chain:

    while( -l $dir ) { $dir = readlink $dir }

    or more concise:

      1 while( -l $dir and $dir=readlink($dir))

    --

    g r i n d e r
Re: Symbolic Links
by nardo (Friar) on Aug 02, 2001 at 20:37 UTC
    You can use readlink to read where a symlink points, but it won't necessarily be the final destination since it can point to another symlink.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://101705]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-10-12 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.