Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 09-23-2005, 08:02 AM   #1
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:

it would return the resolved links, which would be:


or more simply:

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.

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

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

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

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
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
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.

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

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


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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:33 PM.

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