LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-28-2008, 12:15 PM   #1
rlinuxr
Member
 
Registered: Jul 2003
Posts: 35

Rep: Reputation: 15
Printing full path name for sym links using ls command


Oracle Enterprise Linux 5
# cat /etc/redhat-release
Enterprise Linux Enterprise Linux Server release 5.2 (Carthage)

How do I get the 'ls' command to display the full target path for a symbolic link? For example:

ls -la /dev/iscsi/*

/dev/iscsi/data:
total 0
drwxr-xr-x 2 root root 60 Aug 27 13:48 .
drwxr-xr-x 7 root root 140 Aug 27 13:48 ..
lrwxrwxrwx 1 root root 9 Aug 27 13:48 part -> ../../sde

How do I get the full path name instead of "../../sde"?

Thanks.

Last edited by rlinuxr; 08-28-2008 at 12:16 PM. Reason: Grammer
 
Old 08-29-2008, 05:05 AM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 197Reputation: 197
I don't think you can. What is displayed is the path that was specified when the link was created. E.g.

Code:
mike@continuity:/tmp$ mkdir -p blah/gah/wah
mike@continuity:/tmp$ touch foo
mike@continuity:/tmp$ cd blah/gah/wah/
mike@continuity:/tmp/blah/gah/wah$ ln -s /tmp/foo foolink_absolute
mike@continuity:/tmp/blah/gah/wah$ ln -s ../../../foo foolink_relative
mike@continuity:/tmp/blah/gah/wah$ ls -l
total 0
lrwxrwxrwx 1 mike mike  8 2008-08-29 09:59 foolink_absolute -> /tmp/foo
lrwxrwxrwx 1 mike mike 12 2008-08-29 10:00 foolink_relative -> ../../../foo
If the link was created using relative path then you have to infer it from the location of the link. In your example part is a link to /dev/sde
 
Old 08-29-2008, 05:23 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
Learn something new everyday!!

I see one advantage of doing links this way: You can make links within a directory/subdirectory then you can move the whole directory somewhere else and the links are still valid.
 
Old 08-29-2008, 05:31 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Quote:
Originally Posted by pixellany View Post
Learn something new everyday!!

I see one advantage of doing links this way: You can make links within a directory/subdirectory then you can move the whole directory somewhere else and the links are still valid.
Trying on Fedora 9... using a relative path, it does not work on my system. Maybe some shell option to tweak...

Hey, pixellany... you're a moderator now! Congratulations! Are you planning to make a party to celebrate?
 
Old 08-29-2008, 09:12 AM   #5
rlinuxr
Member
 
Registered: Jul 2003
Posts: 35

Original Poster
Rep: Reputation: 15
Thanks everyone.

The link is actually being created using udev rules.

Code:
KERNEL=="sd[a-z]", BUS=="scsi", PROGRAM="/etc/udev/scripts/iscsidev.sh %b", SYMLINK+="iscsi/%c/part"
 
Old 08-29-2008, 09:20 AM   #6
tethysgods
Member
 
Registered: May 2004
Posts: 166

Rep: Reputation: 17
ls command

If I understand the question....

use "ls -l" rather than just "ls"
 
Old 08-29-2008, 10:07 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
You'd have to use a shell pipe:
Code:
ls -l | sed -n 's/^.* -> //p' | while read l; do echo "$(cd "$(dirname "$l")" >/dev/null && pwd)/$(basename "$l")"; done
Yves.

Last edited by theYinYeti; 08-29-2008 at 10:11 AM. Reason: take non-directories into account
 
Old 08-30-2008, 12:05 PM   #8
rlinuxr
Member
 
Registered: Jul 2003
Posts: 35

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by theYinYeti View Post
You'd have to use a shell pipe:
Code:
ls -l | sed -n 's/^.* -> //p' | while read l; do echo "$(cd "$(dirname "$l")" >/dev/null && pwd)/$(basename "$l")"; done
Yves.
Unfortunately, that does not work.

Code:
ls -l /dev/iscsi/* | sed -n 's/^.* -> //p' | while read l; do echo "$(cd "$(dirname "$l")" >/dev/null && pwd)/$(basename "$l")"; done
//sdb
//sdc
//sdd
//sdf
//sde
 
Old 08-31-2008, 03:32 AM   #9
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Why use ls for this ?
readlink -f good a pretty good job
 
Old 08-31-2008, 11:25 AM   #10
rlinuxr
Member
 
Registered: Jul 2003
Posts: 35

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Valery Reznic View Post
Why use ls for this ?
readlink -f good a pretty good job
I was not aware of this command. It works.

Code:
# cd /dev/iscsi/data
# ll
total 0
lrwxrwxrwx 1 root root 9 Aug 27 13:48 part -> ../../sdb
# readlink -f part
/dev/sdb
Thanks Valery and thanks every else for their suggestions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sym links and permissions emme0032 Linux - Newbie 2 11-18-2006 03:26 AM
Sym links and hard links akudewan Linux - Newbie 4 02-09-2005 06:08 AM
sym links -- RealPlayer lmellen Linux - Newbie 2 08-29-2004 03:29 PM
Dead sym links Hangdog42 Linux - General 5 10-02-2003 05:35 AM
Sym Links and vsFTPd Datacraft Linux - Software 1 05-24-2003 06:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration