Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the Absolute Path for symlink file?

Tags:

perl

# test-> a.pl

my $file = '/home/joe/test';
if ( -f $file && -l $file )  {
    print readlink( $file ) ;
}

how to get the Absolute Path for symlink file ?

like image 388
Tree Avatar asked Feb 03 '11 14:02

Tree


People also ask

How do I find the absolute path of a file?

The getAbsolutePath() method is a part of File class. This function returns the absolute pathname of the given file object. If the pathname of the file object is absolute then it simply returns the path of the current file object.

Are symlinks relative or absolute?

Symbolic links can either be absolute or relative links. Absolute links are links that specify each portion of the path name; relative links are determined relative to where relative–link specifiers are in a specified path.

How do you find the source of a symbolic linked file in Linux?

1 Answer. Show activity on this post. Long answer: to find the name of the actual file/folder that a symbolic link points to, check the info after the -> in the ls -l command. The link passwd in your example is a relative link.


1 Answers

Cwd provides such functionality by abs_path.

#!/usr/bin/perl -w

use Cwd 'abs_path';

my $file='/home/joe/test';
if( -f $file && -l $file ) {
    print abs_path($file);
}
like image 59
vtorhonen Avatar answered Sep 18 '22 16:09

vtorhonen