Searching On A Mac

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.
oo7mlAsked:
Who is Participating?
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
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
 
Big MontyConnect With a Mentor Senior Web Developer / CEO of ExchangeTree.org Commented:
here is a visual representation to use the Find command

http://support.apple.com/kb/ht2350
0
 
strungConnect With a Mentor Commented:
There is an Apple KB with a comprehensive explanation of how do use Spotlight to search:

http://support.apple.com/kb/ht2531
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
oo7mlAuthor Commented:
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
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
do you have finder pointing to your website folder?
0
 
Eoin OSullivanConnect With a Mentor ConsultantCommented:
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
 
strungCommented:
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
 
strungCommented:
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
 
strungCommented:
Just beat me to it, Eoin!   :-)
0
 
oo7mlAuthor Commented:
Cool, thanks guys, appreciate the help... will try this as soon as i get home, thanks
0
 
Eoin OSullivanConsultantCommented:
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
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
>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
 
Eoin OSullivanConsultantCommented:
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
 
oo7mlAuthor Commented:
Thanks, i have found it does work well if you click into the folder you are searching for and then work from there.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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
 
strungCommented:
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
 
serialbandConnect With a Mentor Commented:
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
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
This year, I am going to learn to use terminal!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.