Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Searching with grep & Spotlight's kMDItemDisplayName (See related posts)


# first a grep regex:
# only match the last part of a complete file path

mdfind '*==*' | grep -i -E '/[^/]*?somestring[^/]*?[0-5][^/]*?$' | sed 's/ /\\ /g' | xargs basename


# let Spotlight search for the fixed part of the search string, and grep for the variable one

mdfind 'kMDItemDisplayName == "*somestring*"wc' | grep -i -E '/[^/]*?[0-5][^/]*?$'



# To search for folders add:
mdfind 'kMDItemKind == "Folder" && kMDItemDisplayName == ...' ...


# To search for files you may add, for example:
mdfind '( kMDItemKind == "*text*"wc || kMDItemKind == "*document*"wc || kMDItemKind == "*image*"wc ) && kMDItemDisplayName == ...' ...


# ... or just ...
mdfind 'kMDItemKind != "Folder" && kMDItemDisplayName == ...' ...




You need to create an account or log in to post comments to this site.


Related Posts