# 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 ?
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.
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With