Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Doing specific searches

Doing specific searches
Thread Tools
Senior User
Join Date: Jul 2006
Status: Offline
Reply With Quote
Nov 6, 2006, 01:27 PM
 
How do I search for a specific type of document containing a specific word within a particular directory and its subdirectories? For instance, I want to find .css documents with the word "window" in a directory called "Global", and its subdirectories.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 6, 2006, 03:03 PM
 
Go to the directory called Global, hit Find, choose Kind: Cascading Style Sheets and Name: window. Or does that not work for some reason?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Senior User
Join Date: Jul 2006
Status: Offline
Reply With Quote
Nov 6, 2006, 05:11 PM
 
Originally Posted by Chuckit View Post
Go to the directory called Global, hit Find, choose Kind: Cascading Style Sheets and Name: window. Or does that not work for some reason?
No, that does not work. Should it not be Contents: window? Anyway, that did not work either. If I do the search as Kind: Others... Cascading Style Sheet file with Contents as window, it does not fetch anything. I know that word is in some of those files.
     
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Nov 9, 2006, 07:02 AM
 
cd ~/The/Path/To/Global
find . -name "*.css" -exec grep -q window {} ';' -print

If you want that explained let me know.
     
Senior User
Join Date: Jul 2006
Status: Offline
Reply With Quote
Nov 9, 2006, 01:16 PM
 
Originally Posted by WJMoore View Post
cd ~/The/Path/To/Global
find . -name "*.css" -exec grep -q window {} ';' -print

If you want that explained let me know.
I understand everything up to and including the word "window". Why the braces and the semicolon enclosed in single quotes? Why the "-print"? I do not want to print the list, I just want to see it on the screen and refer to it.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 9, 2006, 01:38 PM
 
The -exec argument executes the following arguments (up to the semicolon) as a command. The "{}" inserts the name of the current matched file, and the semicolon is in quotes because otherwise the shell would interpret it (and prematurely end the command!) instead of passing it literally to the find command. The -print means to print the results to the screen.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Nov 9, 2006, 02:48 PM
 
What he said
     
Senior User
Join Date: Jul 2006
Status: Offline
Reply With Quote
Nov 10, 2006, 03:47 PM
 
Thanks for the help, people.
     
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 10, 2006, 04:07 PM
 
So complicated.

Why not just open the Global window and type "window .css" into the Spotlight field?

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Nov 10, 2006, 06:22 PM
 
Depends on your point of view. I work with UNIX every day at work so using find is just automatic. Plus I don't trust Spotlight all the time because even if a file just contains text it must be of a known extension to get indexed. I learnt this the hard way when I was trying to find a CUE file that contained the name of a certain song. Spotlight never found it because it didn't index cue files. find however came to the rescue. BTW this is the case with CSS files, they aren't indexed by default:
Code:
wmoore$ mdls afile.css afile.css ------------- kMDItemAttributeChangeDate = 2006-11-11 11:14:10 +1100 kMDItemContentCreationDate = 2006-11-10 00:00:42 +1100 kMDItemContentModificationDate = 2006-11-10 00:00:42 +1100 kMDItemContentType = "dyn.ah62d4rv4ge80g65x" kMDItemContentTypeTree = ("public.data", "public.item") kMDItemDisplayName = "afile.css" kMDItemFSContentChangeDate = 2006-11-10 00:00:42 +1100 kMDItemFSCreationDate = 2006-11-10 00:00:42 +1100 kMDItemFSCreatorCode = 0 kMDItemFSFinderFlags = 0 kMDItemFSInvisible = 0 kMDItemFSIsExtensionHidden = 0 kMDItemFSLabel = 0 kMDItemFSName = "afile.css" kMDItemFSNodeCount = 0 kMDItemFSOwnerGroupID = 501 kMDItemFSOwnerUserID = 501 kMDItemFSSize = 7 kMDItemFSTypeCode = 0 kMDItemID = 65300 kMDItemKind = "CSS style sheet" kMDItemLastUsedDate = 2006-11-11 11:14:10 +1100 kMDItemUsedDates = (2006-11-10 00:00:42 +1100, 2006-11-11 11:00:00 +1100)
The same file renamed to .txt gives:

Code:
wmoore$ mdls afile.txt afile.txt ------------- kMDItemAttributeChangeDate = 2006-11-11 11:17:12 +1100 kMDItemContentCreationDate = 2006-11-11 11:17:12 +1100 kMDItemContentModificationDate = 2006-11-11 11:17:12 +1100 kMDItemContentType = "public.plain-text" kMDItemContentTypeTree = ( "public.plain-text", "public.text", "public.data", "public.item", "public.content" ) kMDItemDisplayName = "afile.txt" kMDItemFSContentChangeDate = 2006-11-11 11:17:12 +1100 kMDItemFSCreationDate = 2006-11-11 11:17:12 +1100 kMDItemFSCreatorCode = 0 kMDItemFSFinderFlags = 0 kMDItemFSInvisible = 0 kMDItemFSIsExtensionHidden = 0 kMDItemFSLabel = 0 kMDItemFSName = "afile.txt" kMDItemFSNodeCount = 0 kMDItemFSOwnerGroupID = 501 kMDItemFSOwnerUserID = 501 kMDItemFSSize = 7 kMDItemFSTypeCode = 0 kMDItemID = 65765 kMDItemKind = "Plain text document" kMDItemLastUsedDate = 2006-11-11 11:17:12 +1100 kMDItemUsedDates = (2006-11-11 11:17:12 +1100)
Note that it now has a known content type (kMDItemContentType). There is an easy solution to this. The Spotlight preferences should allow a type to added to an existing content importer. This can be done manually by editing the content importer but shouldn't be necessary.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:47 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2