Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the real path from a link 1

Status
Not open for further replies.

cruel

Programmer
Aug 6, 2001
131
If a link is for a directory, how would one get the real path. It must be very simple but it just never came across me.
 
Depending on what operating system, you can use "file":

$ file /var/mail
/var/mail: symbolic link to spool/mail

 
An easy way to get a compete listing:
ls -l $dir | awk ' /->/ {printf "%s = %s\n",$(NF - 2), $NF}'
 
Thanks. However, excuse me for failing to explain in more details. Suppose I see a directory:
/d1/f1
/d1/f2

and I see a link
/d1_ln -> /d1

now if you test d1_ln, it shows it is a link. If you test /d1_ln/f1, it is not a link anymore. I do not know why things are being set up this way, but I need to show that /d1_ln/f1 is actually /d1/f1. I guess one could test each level of directory, but I am wondering if there is a more straightforward way to test this, especially built-in command?
 
In ksh you can use
Code:
pwd -P
or
Code:
pwd -L
to see the real path or the logical path

Hope This Help
PH.
 
That is terrific. I do not know why I neven try to man pwd. pwd -P works on my system. Thanks all
 
That's a good one, PHV! Found the -L and -P options described under the manual pages for "bash" where I've never noted them before. That gets a star as a helpful post. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top