Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my ~ dir, I have some symlinks that point to "/Volumes/Macintosh HD 2/..." and I want to find them all recursively. A look at the man page for 'find' says the '-lname' argument will search the symbolic link contents. It appears to work, but not recursively:

$ pwd
/Users/myusername
$ sudo find . -lname '/Volumes*' 
$ cd Documents/
$ sudo find . -lname '/Volumes*' 
./Documents on Win7
./work.rtf

What's going on? How can I make this work recursively? -- The 'find' program is supposed to always work recursively.

I checked perms, they look ok, but as you can see I used "sudo" just to be sure... no dice.

$ ls -ld Documents/
drwx------+ 14 myusername  staff  476 Jan 12 16:32 Documents/
share|improve this question

1 Answer 1

up vote 2 down vote accepted

It looks like a bug in the way the -lname predicate is tested, and it's much weirder than just not recursing. From my testing, it seems to only work on files at the same directory depth as the current working directory (i.e. is you were in ~/Documents and ran find .. -lname '/Volumes*', it would find links in ~/Documents and ~/Desktop, etc but NOT any links in ~). But there is (at least according to my testing) a workaround: it seems to work if the starting directory is an absolute path, so using find "$PWD" -lname '/Volumes*' instead of find . -lname '/Volumes*' seems to avoid the problem. Here's a test sequence to illustrate this:

Mac:~ test$ mkdir -p sub1/subsub1 # Create some folders and links to work with
Mac:~ test$ mkdir -p sub2/subsub2
Mac:~ test$ ln -s sometarget toplink
Mac:~ test$ ln -s sometarget sub1/sub1link
Mac:~ test$ ln -s sometarget sub1/subsub1/subsub1link
Mac:~ test$ ln -s sometarget sub2/sub2link
Mac:~ test$ ln -s sometarget sub2/subsub2/subsub2link
Mac:~ test$ find . -lname "*" # This only finds links at the top of the home directory
./toplink
Mac:~ test$ cd sub1
Mac:sub1 test$ find . -lname "*"
./sub1link
Mac:sub1 test$ find .. -lname "*" # This only finds links one level down
../Pictures/iChat Icons
../sub1/sub1link
../sub2/sub2link
Mac:sub1 test$ cd subsub1
Mac:subsub1 test$ find ../.. -lname "*" # This only finds links two levels down
../../sub1/subsub1/subsub1link
../../sub2/subsub2/subsub2link
Mac:subsub1 test$ find ../.. -lname "*" -o -name "*sub2*" # The -name predicate works fine
../../sub1/subsub1/subsub1link
../../sub2
../../sub2/sub2link
../../sub2/subsub2
../../sub2/subsub2/subsub2link
Mac:subsub1 test$ find /Users/test -lname "*" # It works as expected with an absolute starting path
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.AddressBook
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.Dashboard
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.Dock
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.iCal
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.Keychain
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.Mail
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.PreferenceSync
/Users/test/Library/Application Support/SyncServices/Local/clientdata/com.apple.Safari
/Users/test/Pictures/iChat Icons
/Users/test/sub1/sub1link
/Users/test/sub1/subsub1/subsub1link
/Users/test/sub2/sub2link
/Users/test/sub2/subsub2/subsub2link
/Users/test/toplink

I'll submit it to Apple's bugreporter.

share|improve this answer
    
Good job finding that workaround! –  Eddified Jan 15 '11 at 6:13

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.