Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to search a file on a NAS and show path of that file on mac osx

Can anyone help me with a way to search for a file based on a 'contains' description, with a result showing the full path of where the file is.


Please note: File will be deep within a mounted NAS volume.


thanks anyone!

Mac Pro

Posted on Feb 4, 2016 2:05 AM

Reply
20 replies

Feb 4, 2016 9:09 AM in response to Kevlesser

Is this something you need to do once, in which case I bet FindAnyFile could have found it in the time it took me to type this sentence, or is this something you need to do every hour from now to eternity? Also are you really trying to search the contents of a file? EasyFind is also a handy utility. I will let you take the time to read up on the details of their operation but it wouldn't surprise me if the underpinnings were unix search and not just reading the Spotlight database.

Feb 4, 2016 1:50 PM in response to Kevlesser

Spotlight will index files on disk (including their metadata) and make it easily searchable.


However, unless things have changed recently, spotlight won't index network volumes by default. You need to enable indexing via Terminal.app


Open Terminal, and run:


mdutil -i on /Volumes/NAS_DRIVE


(where NAS_DRIVE is the name of the volume mounted off the NAS)


You can check the state of indexing using mdutil -s /Volumes/NAS_DRIVE


Just be aware that a large NAS drive may take many hours to initialize the index.

Feb 5, 2016 3:35 AM in response to Kevlesser

Kevlesser wrote:


Can anyone help me with a way to search for a file based on a 'contains' description, with a result showing the full path of where the file is.



What do you mean by 'contains' description?

Are you searching the contents of the file, or is it a description in the metadata?

If it's in the metadata (you can see a list of the metadata with mdls), then after indexing as Camelot suggested, use mdfind (see man mdfind): mdfind [-live] [-count] [-onlyin directory] [-name fileName] query

For example, to find all files that contain "MyFavoriteAuthor" in the kMDItemAuthor metadata attribute, use: mdfind "kMDItemAuthors == '*MyFavoriteAuthor*'"

Feb 12, 2016 12:33 PM in response to Tony T1

On second read, I'm not sure if you want to find a file by name, or a Folder name.

If a file, change:

-type d

to

-type f

so:

find /Volumes/NAZ -type f -iname '*phrase to search*'


…or don't use type at all to include files and folders in search.


Also, as per Camelot's suggestion (Re: How to search a file on a NAS and show path of that file on mac osx),

it should be faster to index the NAZ and use mdfind (instead of find):


mdfind -onlyin /Volumes/NAZ -name 'phrase to search'


Note: don't use wildcards with mdfind.

Feb 12, 2016 12:51 PM in response to Kevlesser

Kevlesser wrote:


this is good but on a volume with alot of files, every search takes ages to find anything, i thought by doing it through maybe a terminal command it may find it quicker....

What files types are you talking about?


If it is a plain text file 'grep' will find words within a file, however it will still have to traverse the entire filesystem.


grep -RI "Stuff" /Volumes/MY-NAS

-R = recurse directores

-I (uppercase i) = ignore binary files.


Will find 'Stuff' in /volumes/MY-NAS (case sensitive).

You can tweak the output options to get full paths etc

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/ man1/grep.1.html


I'm unsure how well Spotlight indexing works on NAS's you may find that one client kills the entire index that another client created, normally the index is managed on an OS X server that hosts that share. File permissions & ACL's may make it interesting in a multi user environment.


Are others here indexing NAS's via Spotlight?

Feb 12, 2016 1:13 PM in response to Drew Reece

Drew Reece wrote:


Kevlesser wrote:


this is good but on a volume with alot of files, every search takes ages to find anything, i thought by doing it through maybe a terminal command it may find it quicker....

What files types are you talking about?


If it is a plain text file 'grep' will find words within a file, however it will still have to traverse the entire filesystem.



Looks like he's just searching for a name, not the contents. find (or mdfind if indexed) will be his best bet

see my response below: Re: How to search a file on a NAS and show path of that file on mac osx

How to search a file on a NAS and show path of that file on mac osx

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.