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

1 Answer 1

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 .

4
  • Is it possible to use command in spotlight?
    – Wizard
    Commented Nov 28, 2017 at 3:36
  • @JoseTronco Do you mean from the command line - yes, you can use the -onlyin option.
    – Scot
    Commented Nov 28, 2017 at 3:41
  • from search bar after press command + 'space'.
    – Wizard
    Commented Nov 28, 2017 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
    Commented Nov 28, 2017 at 4:09

You must log in to answer this question.

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