Timeline for Is there any way to make mdfind (the spotlight command line) find symlinks?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 6, 2022 at 3:53 | comment | added | Allan |
Spotlight indexes files that it’s configured to index and find. If you use the find command, it will find symlinks just fine.
|
|
Dec 6, 2022 at 1:38 | comment | added | Gilby | @Allan I find the adage a bit meaningless when you get to details. Spotlight indexes files, not inodes. An inode belonging to a file contains pointers to data blocks which are the file content which is indexed by Spotlight. The inode for a symlink contains a pointer to the linked file - it does not have any file data. Hence reasonable for the linked file to be indexed and not the symlink. Anyway this is just splitting hairs about the second sentence - it doesn't change the rest of the answer. | |
Dec 5, 2022 at 22:23 | comment | added | Allan |
A symlink is a file object type so the adage “everything is a file in Unix” can and still applies. If you get the inode number of the file (ls -i foo.bar where foo.bar is a symlink) you will see that it’s a valid object and can be treated as such. I think you may be conflating the partitioning scheme (FAT, APFS, NTFS, etc.) and how it maps to files via pointers versus the OS file system and how it handles the objects contained in it’s file system.
|
|
Dec 2, 2022 at 1:45 | comment | added | Gilby | @Allan I am very much not an expert on file systems, but my understanding is that at one time unix systems did store symlinks in files, but that this is no longer true. Most POSIX systems implement fast symlinks and store a pointer in the file system. The size reported for a symlink is the size of the pointer. This simplicity of symlinks is the main advantage over aliases which are stored as files. | |
Dec 2, 2022 at 0:48 | comment | added | JL Peyret |
So, generate checklist as README.md and then ln -s README.md checklist.md . mdfind still finds its files. Still, an annoyance in mdfind . I am well aware of find usage, in fact I used find . -name README.md -type l to identify where I had this problem. The only thing is mdfind is awesomely faster... when it works as expected. I'll leave this out for a while. If no one else contradicts you and has a better solution then I'll accept it later. Upvoted.
|
|
Dec 2, 2022 at 0:45 | comment | added | JL Peyret |
Yeah, aside from the "not a file" claim, you're probably right. symlinks seem to be 2nd class citizens to Spotlight. FWIW mdls returns the same metadata for the symlink as for the file. What I've ended doing is inverting which files are real and which symlinks: my organization is to track issues as directories under a certain location with a README.md file. Then I came with a way to generate checklist.md as a reminder of things I needed to fix. So ln -s checklist.md README.md and I've got both my readme and my checklist, right? Wrong, mdfind finds no README.md .
|
|
Dec 1, 2022 at 23:23 | comment | added | Allan | In Unix and Linux, everything is considered a file including symlinks. It’s just symlinks are a file type that is not indexed by Spotlight. | |
Dec 1, 2022 at 22:35 | history | answered | Gilby | CC BY-SA 4.0 |