4

underwhelmed by the fact that OS X’s Aliases got really big with Mountain Lion (Lion?) I basically switched to using symbolic links instead.

Now I’m just learning the hard way that Spotlight (or, Finder for that matter; since Finder’s find relies on Spotlight) doesn’t index symbolic links (or, their names). I.e., when you look for a specific string/word in the name of a symbolic link (by way of Finder’s search-field) nothing shows up. This is different from Aliases (’s names), which do show up.

This is very bad for me and I’m looking for a way to make Spotlight index symbolic links (some mdimporter magic?), or to be able to search for (the names of) symbolic links in some other way.

You see, I’m using the symbolic links mostly to link to larger files that reside on eternal hard drives in order to save space on my internal drive. But I really need to find these files (by searching their respective folders) by entering some search term that matches their name.

I’m searching for (the names of) the linked files, not for the symbolic link-files themselves; that’s why a solution like proposed here:

http://arstechnica.com/civis/viewtopic.php?f=19&t=1109635

doesn’t help me. If I understand correctly.

Over the last weeks (after switching to Mountain Lion from Snow Leopard) I created lots of symbolic links that are now invisible to any search functionality.

4
  • I have the same problem, and I need a way to make the native Finder/Spotlight find symlinks, not a CLI solution. Did you ever find a way to make Spotlight index symlinks?
    – JVC
    Jul 5, 2015 at 6:32
  • You can search for any normal file with Spotlight. The fact that this file name is pointed by a symbolic name or an alias doesn't change your possibilities to find it by its "target name". Please clarify your question.
    – dan
    Jul 8, 2015 at 19:18
  • @ Jonathan van Cute -unfortunately Spotlight isn't going to work for you. t
    – fd0
    Jul 8, 2015 at 20:40
  • @danielAzuelos Actually no, Finder (Spotlight) is not able to locate symlinks, period. Not by name, not by type, not by anything. That's the whole problem as clearly indicated in the original question. @ fd0 The problem is, I have no option to not use Spotlight. Other apps I use, are also not able to see symlinks, and it appears to be because they also leverage Spotlight. In particular I use Path Finder as a "replacement" for Finder (more of an addition really) and the developer has given me some indication that it should be able to find them, but as yet no joy. Any other suggestions?
    – JVC
    Jul 11, 2015 at 4:52

1 Answer 1

1

You can use the find command to show you the target of the symlink then have awk throw away the rest of the line. Then wrap that in a loop that tells you what it's doing then feeds the names to mdimport:

for linktarget in $(find ${HOME} -type l -ls | awk -F'-> ' '{print $NF}'); do
    echo "importing ${linktarget}"
    mdimport "${linktarget}"; 
done

It's probably easier to cut and paste this little script since there are some spaces that are easy to miss. (like the one after the arrow in the awk statement).

1
  • This fails on filenames with spaces. And symlinks with relative paths. This fixes the first problem, but will fail on files with newlines: find ~ -type l -ls | awk -F'-> ' '{print $NF}' | tr '\n' '\0' | xargs -0 -n1 mdimport. Feb 26, 2017 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .