3

I aim to search the contents of files at a specified directory.

take an example in spotlight search

'Marked important question' in dir('/desktop)

How can such a task be accomplished?

2

From the Finder

An easy way is to open a Finder Window to the folder of interest, and use the search box in the upper right corner. For this to work effectively, Finder Preferences should be adjusted as follows:

Under Finder/Preferences/Advanced tab, change

When performing a search: to

"Search the Current Folder"

From the Command Line

Use mdfind, with the -onlyin option, as below, which will search the current directory for all files with a .jpg suffix:

mdfind -name .jpg -onlyin .

  • Is it possible to use command in spotlight? – Algebra Nov 28 '17 at 3:36
  • @JoseTronco Do you mean from the command line - yes, you can use the -onlyin option. – Scot Nov 28 '17 at 3:41
  • from search bar after press command + 'space'. – Algebra Nov 28 '17 at 3:43
  • I'm not sure if this is possible with Apple's built-in Spotlight GUI (there is a specifier entitled kMDItemPath. But, it doesn't appear to work as you desire: see apple.stackexchange.com/questions/70939/… – Scot Nov 28 '17 at 4:09

You must log in to answer this question.

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