Solved

Searching On A Mac

Posted on 2014-01-22
19
221 Views
Last Modified: 2014-02-11
Hi, is it possible to search a full folder of files and sub folders, for a particular word that is in a file.

For example, i am trying to find a file that contains a function in a line of code for a client and i can't seem to locate which file it is in. I have the client's site in a folder with about 200 files (mixture of php, html, js, css) and sub folders.

Is it possible to search for a string at the top level of the folder? Thanks in advance.
0
Comment
Question by:oo7ml
  • 6
  • 4
  • 3
  • +3
19 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 150 total points
ID: 39799864
If you open a new finder window and enter a search term, it will search that term in both the file contents and file name.  If you need to be more specific, you can click the plus sign int he finder window (right side under the "save" and you will expose a couple of drop downs that can help you narrow your search.
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 50 total points
ID: 39799886
here is a visual representation to use the Find command

http://support.apple.com/kb/ht2350
0
 
LVL 53

Assisted Solution

by:strung
strung earned 50 total points
ID: 39799888
There is an Apple KB with a comprehensive explanation of how do use Spotlight to search:

http://support.apple.com/kb/ht2531
0
 
LVL 53

Expert Comment

by:strung
ID: 39799896
0
 

Author Comment

by:oo7ml
ID: 39799900
Hi, i have tried this and it does not work for me... let's say a html file has the following line of code

<div class="redbox">

Finder doesn't seem to be able to pick up that line in my website folder, however i know it is there?
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39799903
do you have finder pointing to your website folder?
0
 
LVL 39

Assisted Solution

by:Eoin OSullivan
Eoin OSullivan earned 150 total points
ID: 39799912
Personally I don't trust the Spotlight search for in-file content it is SLOW and inaccurate.

Instead get your hands on this FREE OSX application called EasyFind
http://www.devontechnologies.com/products/freeware.html

It can search for filenames, or text in files .. you can restrict your search to specific folders, include/exclude hidden files and more.

More importantly it is FAST and accurate .. the guys who develop it specialise in document management systems so they know what they are doing.

You can also use the great FREE text editor TextWrangler which has multi-file search and wildcard grep support and it is also good for code editing
http://www.barebones.com/products/textwrangler/

The other option is to use the UNIX find command with a grep or awk parameter but it is not the most intuitive or easy to visualise the results.
0
 
LVL 53

Expert Comment

by:strung
ID: 39799920
The quotes may be confusing it.  Try a boolean search like:

"div class=" and "red box"

http://support.apple.com/kb/PH4332?viewlocale=en_US
0
 
LVL 53

Expert Comment

by:strung
ID: 39799926
Better still, download the freeware Textwrangler:  http://www.barebones.com/products/textwrangler/

It will allow you to search a particular folder for specific text in a file and will even allow you to do a global search and replace on all files in the folder.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 53

Expert Comment

by:strung
ID: 39799929
Just beat me to it, Eoin!   :-)
0
 

Author Comment

by:oo7ml
ID: 39799934
Cool, thanks guys, appreciate the help... will try this as soon as i get home, thanks
0
 
LVL 39

Expert Comment

by:Eoin OSullivan
ID: 39799962
Spotlight is OK for searching by the filename only and only within your user home folder .. for system or hidden files, contents of ZIP archives or text within files it is hard to beat EasyFind.  Every OSX user should have it in their utility belt.

TextWrangler is your best bet if you want to edit the files after you've searched for them .. it is quite a good web editor and the text search is reliable.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39799963
>visual representation to use the Find command

Big M, what year are we in now?  Or should I say decade?  :)

oo7ml, the finder does all of this.  I agree spotlight is sketchy.  I use finder all the time for the very same thing.   You do want to make sure you are searching in the correct folder.  Towards the top you have a choice.  Sometimes it does help to be in the folder you actually need rather then the top level.  

Try going to a page, copy some text you want to search for, then paste to the finder (not spotlight) and see what happens.
0
 
LVL 39

Expert Comment

by:Eoin OSullivan
ID: 39799975
padas > the ability of spotlight to search for html type code in a series of nested folders can be a "disaster".  If you want to search a folder and all its subfolders for something like "class='redbox'" I'd never trust spotlight to get it correct whereas I would trust TextWrangler or EasyFind
0
 

Author Comment

by:oo7ml
ID: 39799978
Thanks, i have found it does work well if you click into the folder you are searching for and then work from there.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39800011
eoinosullivan, I agree, I said spotlight is sketchy.   I never knew (bothered to look) that TextWrangler would find other files.   But it would just use the finder info.  If you happen to work in TW, that is probably a good choice for you.  Outside of that, finder does the trick.

oo7ml, glad you figured it out.
0
 
LVL 53

Expert Comment

by:strung
ID: 39800130
TW will also let you a global search and replace of all occurrences of a phrase inside all files in the folder, so, for instance, 007 could with one keystroke do a global replace of all instances of <div class="red box"> with <div class="green box">.
0
 
LVL 27

Assisted Solution

by:serialband
serialband earned 100 total points
ID: 39802092
OSX is based on NeXT, which is based on BSD unix, so you can also use the good old fashioned, built-in, unix/linux way.  

First, open /Application/Utilities/Terminal.app

If you're looking in the user's Downloads folder, then run this command line.

Search all files recursively with -R option in /Users/007ml/Downloads.
cd /Users/007ml/Downloads/
grep -R "search string" *


Here's another example to narrow the search to all files ending with txt, js, css, or html within the user's Documents folder.
grep -R "search string" /Users/007ml/Downloads/*{txt,js,css,html}


Another example for searhing files that have a single digit number before the file extension.
grep -R "search string" /Users/007ml/Downloads/*[0-9].*{txt,js,css,html}


Unix was built for searching and manipulating text.  Once you find what you're searching for, you can swap terms with sed or awk.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39802743
This year, I am going to learn to use terminal!
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The error "There was an error performing the update" occurred on a Mac OS X client workstation running  Symantec AntiVirus for Mac (http://www.symantec.com/business/products/purchasing.jsp?pcid=pcat_security&pvid=825_1) - the Enterprise product vers…
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now