Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have several directories that all have various symlinks in them. I want find (or another program) to find based on where the symlinks point to. For example this is how it currently works:

└─(11:05:%)── ll slink
lrwxrwxrwx 1 dialout 9 2010-11-03 11:05 slink -> /opt/file
└─(11:05:%)── find / -name 'file'

This is what I'd like to be able to do

└─(11:05:%)── find . -name 'file'
/slink -> /opt/file
share|improve this question

1 Answer 1

up vote 3 down vote accepted
find . -L -name 'file'

-L means follow symbolic links and according to man it takes properties from this file. Alternativly you can write:

find . -lname 'file'

The second option will work with broken links.

share|improve this answer
1  
I was just writing the same thing. I think -lname is better; -L will cause it to follow symlinks and to return normal files with the given name, while -lname is exactly the desired behavior. It won't match in this case though because the symlink's target is /opt/file, so you need to either do find . -lname '/opt/file' or find . -lname '*/file' –  Michael Mrozek Nov 3 '10 at 18:22
    
This works, except the find on the busybox machine I was working on didn't have the -L parameter =\ –  Falmarri Nov 12 '10 at 19:20
    
I think the first option is better dealt with at serverfault.com/a/87643/96883 –  artfulrobot Jun 30 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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