LinuxQuestions.org
Help answer threads with 0 replies.
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 09-23-2005, 08:02 AM   #1
ttilt
Member
 
Registered: Dec 2003
Location: Campinas, Brasil
Distribution: slackware 10
Posts: 150

Rep: Reputation: 15
cmd to resolve symbolic links


is there a cmd to resolve symbolic links in a given path?

for example, if
dir1 -> dir2,
dir3 -> ../
dir4 -> dir5

then if i gave the cmd this path:
dir1/dir3/dir4

it would return the resolved links, which would be:

dir2/../dir5

or more simply:
dir5

If anyone knows of such a cmd let me know, I'm writing this in shell script, but there are a lot of considerations to take into account.

thanks,
JC
 
Old 09-23-2005, 09:01 AM   #2
mschutte
Member
 
Registered: Jan 2005
Location: Innsbruck, Austria
Distribution: Debian GNU/Linux Lenny
Posts: 68

Rep: Reputation: 15
Try
$ stat -L -c%n $SYMLINK
which means:
-L follow the symbolic link
-c%n Only show the file name

Hope I could help,
mschutte
 
Old 09-23-2005, 09:35 AM   #3
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,995
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
ttilt - Thanks for the stat command - wasn't aware of it.

However doing what you said on my system it returned the name of the link rather than the name of the file the link points to which is what I think mschutte was asking for.

A quick way to do it would be:

ls -l file |awk '{print $NF}'

The ls -l would show the file and its link - the awk would break the line up into fields (using whitespace as the delimiter) and the $NF would tell it to print the last field which would be the file to which the link is pointing.

You could create this as a function within your script to use it multiple times.
 
Old 08-01-2010, 08:17 AM   #4
langner
LQ Newbie
 
Registered: Aug 2010
Location: Netherlands
Distribution: Debian
Posts: 9

Rep: Reputation: 0
It's been a while since the question was asked, but you can also use readlink from the GNU core utilities, which is meant to do just this.

Code:
$ touch a
$ ln -s a b
$ ls -l b
lrwxrwxrwx 1 langner langner 1 Aug  1 15:12 b -> a
$ readlink b
a

Last edited by langner; 08-01-2010 at 09:36 AM.
 
  


Reply

Tags
coreutils, links


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
Lost all my rc.d links by cleanlinks cmd Rajns Red Hat 1 04-09-2005 07:11 AM
vsftpd - Cannot resolve symbolic link in browser chpchai Linux - Networking 13 05-26-2004 11:07 PM
Symbolic links? TongueTied Linux - Newbie 3 08-27-2003 06:00 AM
Symbolic links pdstatha Programming 1 04-08-2002 09:50 PM
symbolic links winger Linux - General 5 04-06-2002 05:16 PM


All times are GMT -5. The time now is 11:49 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration