Extracting the linked to file name

Rasjid Wilcox rasjidw at austethical.com.au
Wed Nov 14 11:47:03 EST 2001


From: "David Clarke" <gadicath at yahoo.com>
> On Wed, 14 Nov 2001, Rasjid Wilcox wrote:
> >
> > filename=`ll symlink.name | sed s/"->"/\|/ | cut -f 2 -d\|`
> >
>
> Just wondering, do you want the full path of the file the link points
> to?  If you do this should work:
>
> filename=`ls -la linkname | awk '{print $11}'`
>
> If you just want the actual filename, no path, then this should work:
>
> filename=$(basename `ls -la /bin/mt | awk '{print $11}'`)
>
> Not sure if the above will work for anything except bash.
>

This works okay except when the file 'linkname' has spaces it it, such as 'a
silly link name'.

I think I'll use filename=$(basename `perl -e 'print readlink("link with
space")'`)

Thank you all.

Rasjid.





More information about the linux mailing list