Say that I setup a symbolic link:

ln -s /root/Public/mytextfile.txt /root/Public/myothertextfile.txt

is there a way to see what the target of myothertextfile.txt is using the command line?

link|improve this question

75% accept rate
feedback

3 Answers

up vote 9 down vote accepted

readlink /root/Public/myothertextfile.txt

link|improve this answer
feedback

readlink is the command you want. You should look at the man page for the command. Because if you want to follow a chain of symbolic links to the actual file, then you need the -e or -f switch:

[kbrandt@kb: ~/scrap] ln -s foooooo zipzip #fooooo doesn't actually exist                                                                            
[kbrandt@kb: ~/scrap] ln -s zipzip zapzap
[kbrandt@kb: ~/scrap] readlink -f zapzap #follows it, but doesn't let you know the file doesn't actually exist                                                                                 
/home/kbrandt/scrap/foooooo
[kbrandt@kb: ~/scrap] readlink -e zapzap #Follows it, but file not there                                                                                 
[kbrandt@kb: ~/scrap] readlink zapzap #Follows it, but just to the next symlink                                                                                    
zipzip
link|improve this answer
feedback

This will also work:

ls -l /root/Public/myothertextfile.txt

but readlink would be preferred for use in a script rather than parsing ls.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.