Use spotlight to search code on Mac OS X

Source: Internet
Author: User

Using grep to search for code and convenience is the most primitive and commonly used:

? ~ grep ‘NuPlayer‘ -iInr --color ./aosp

'I' indicates case-insensitive, 'I' indicates that binary files are ignored, 'n' indicates the row number of the search result, and 'R' indicates recursive search subdirectories.


However, grep search is a little slow, and there are many ways to speed up the search by creating indexes on the Internet: "Other grep-like tools and indexing Tools"

Mac, which has always been known for user experience, is not missing. 'spotlight 'is an index-based search tool provided by the system. It is easy to use and CTRL + space calls out. If you want to adjust the directory where the search result file is located, press and hold the command key to enter.


'Spotlight 'certainly has a more custom command line version: 'mdfind '. The search command above can be used for this purpose:

? ~ mdfind ‘NuPlayer‘ -onlyin ./aosp | xargs grep ‘NuPlayer‘ -iInr --onlyin ./aosp

The search speed is dozens of times faster than that in Android code. Here, '-onlyin' tells the command to be searched only in this directory, or else it will be searched on the entire hard disk (but it will be very fast). You may wish to make a function in 'bash _ profile:

function fastfind {mdfind [email protected] -onlyin . | xargs grep [email protected] -riIn .;}


Due to index restrictions, the 'mdfind 'search object does not support regular expressions, but these should be enough:

  • Mdfind ''str1 str2 "indicates that str1 and str2 appear simultaneously

  • Mdfind "str1 | str2" indicates that

  • Mdfind "str1-str2 indicates str1 appears but str2 does not appear


For more advanced usage of 'mdfind ', refer to the metadata definition of spotlight and spotlight.

The metadata defined by spotlight is not very easy to understand. However, you can find out the following when you press the 'mdls' command:

?  ~T  mdls ~/Movies/Practise.mp4kMDItemAudioBitRate            = 48kMDItemAudioChannelCount       = 2kMDItemCodecs                  = (    "H.264",    AAC)kMDItemContentCreationDate     = 2012-01-05 21:59:18 +0000kMDItemContentModificationDate = 2012-01-05 21:59:18 +0000kMDItemContentType             = "public.mpeg-4"kMDItemContentTypeTree         = (    "public.mpeg-4",    "public.movie",    "public.audiovisual-content",    "public.data",    "public.item",    "public.content").....kMDItemFSName                  = "Practise.mp4"......?  ~T  mdfind ‘kMDItemCodecs=H.264‘ | grep ‘Practise‘/Users/hong/Movies/Practise.mp4

In spotlight, metadata starting with 'mditem' is used for indexing.

Command Line Control can look at this again: "Use spotlight with command line"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.