Active2 months ago
To add an individual file or files to your search, either type in the full path to the file (for example, 'C: temp test.txt') into the address bar and press enter, or click the file icon to browse to and select the file you wish to add. Here is how you recursively search through a directory of files and list the name(s) of the files that contain a matching string instead of the matched line. Grep -l Switch The -l switch indicates that you want to display the names of files that contain a string that matches your query.
Is there a way to search through all the text files in a folder (and subfolders) for a specific string or bit of text in Mac OS X?
Chealion22.6k77 gold badges6161 silver badges7171 bronze badges
Paul SheldrakePaul Sheldrake1,8191010 gold badges2828 silver badges3030 bronze badges
8 Answers
You can't do this from the spotlight icon in the menu bar. But you can do it with spotlight:
- Navigate to the folder in the finder.
- Type your search in the search bar on the top right of the folder.
- There is a line above the results that says:
Search: This Mac 'Your Folder Name'
Click on the name of your folder to restrict the search to the folder instead of the whole computer, which is what the default selection 'This Mac' does.
Then click the gear icon, choose show search criteria, and change the kind to text files.
ridogiridogi2,65711 gold badge1313 silver badges2424 bronze badges
If you prefer the command line,
You'll need to be (or get) familiar with
slhckgrep
. Read man grep
for more info.171k4949 gold badges476476 silver badges492492 bronze badges
retracileretracile2,34611 gold badge1818 silver badges2222 bronze badges
Very powerful and fast
Description:Mac Dev Centre - The Power of mdfind
Run5k12.5k77 gold badges3636 silver badges5656 bronze badges
user195192user195192
In the upper right hand corner of your screen: Spotlight
BBEdit supports great search, too, in files and folders.
Daniel Beck♦95.4k1212 gold badges241241 silver badges292292 bronze badges
markratledgemarkratledge
c
ignores case. See this answer for an overview of the query format and other attributes.-F
searches for fixed strings instead of regex. -l
only prints the names of the matching files.Community♦
LriLri32.6k55 gold badges9595 silver badges135135 bronze badges
Open Finder
Navigate to the folder you want to search if you have one.
Enter the term you want to search in the search bar in the upper right hand corner. You may need to stretch out the window to see it.
After you start typing or press enter you'll see a section below the search box to the left that says,
Search: This Mac 'Your Folder' Shared
If you want to search your whole computer click on 'This Mac'. Otherwise click on the folder name next to it. It may already be selected.
To the right side of those options is a 'Save' button with a plus sign next to it.
Click the plus sign. You'll see two drop down lists. In the first one select 'Kind'. In the second choose 'Any' or 'Text .
Choosing 'Any' may find more matches, while 'Text' will find files Mac OS X determines fall under the category 'Text'.
The number of search results will appear at the footer if the footer is shown.
FYI I've noticed that sometimes it takes time to do a search and sometimes there is no indication Finder is doing anything. I wouldn't wait too long but if you're searching a small folder it should be very quick. If searching your Mac it may take up to a minute or more.
Nota bene: To find an exact phrase enclose it in quotes.
1.21 gigawatts1.21 gigawatts95755 gold badges2323 silver badges4848 bronze badges
I'd suggest you look at File Content Finder on the App Store (disclaimer - I'm its developer). John forsythes 5000+ photoshop text effects & layer styles for mac/pc. It's an affordable app specifically designed for searching file contents without indexing. It supports text files and other major file formats (pdf, doc(x), xls(x), etc).
Its filtering lets you optimise and refine your search by multiple criteria - file type, creation/modification dates, etc.
Here is a detailed documentation on how it works.
Geo SystemsGeo Systems
For the faster search speed, you can use
ag
(the silver searcher)Installation:
brew install the_silver_searcher
Usage is alike, just replace the
grep
to ag
For example,
ag 'my string of text' -R .
More information can view on Github.
AsoulAsoul
protected by Community♦Jul 2 at 6:27
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged macosmacsearch or ask your own question.
Active1 year, 11 months ago
Is there any utility to make searches for a string inside ASCII files to avoid command line searches?
How to make a command line search, for example for the string 'test' inside all files in the directory
Braiam/var/x/
?54.1k2121 gold badges144144 silver badges230230 bronze badges
NunoNuno
7 Answers
You can use searchmonkey. The tool is available in the repositories, so you can simply
On the other hand, command line search with grep is really intended for that..
Here is a screenshot from searchmonkey
Anwar59.2k2525 gold badges160160 silver badges264264 bronze badges
alcialci3,25055 gold badges3232 silver badges5656 bronze badges
I assume that your first question is about a GUI alternative to the
grep
command. I can't help you with that, I always find the command line very effective.As for the command line, try
If you want to search recursively (i.e. not only in
/var/x/
, but also in subdirectories thereof), doTo avoid grepping the files which grep thinks to be binary, use the
-I
option:If grep thinks a file is binary (based on first few bytes of the file), it will assume it does not match instead of going through the whole file.
JanuaryJanuary27k1111 gold badges7070 silver badges9292 bronze badges
You can use regexxer it is a great GUI search/replace tool for regular expressions.
you can download by:
Seth♦37.4k2727 gold badges121121 silver badges177177 bronze badges
user61928
You can use the
grep
command from terminal:grep -r string *
This command will find all occurrences of 'string' in all the files under the current directory (or subdrectories).
For hidden files, you can use:
grep -r string .
inquisitiveinquisitive
Try Recoll, best GUI one I ever used. To install recoll in all currently supported versions of Ubuntu open the terminal and type:
How To Search A Mac For Files Containing A Text Phases
It needs some time to index the files first (you can define blacklist path or extensions or mime).
karel67.6k1414 gold badges150150 silver badges170170 bronze badges
user244846user244846
Unfortunately grep does a very poor job of searching inside Word (.doc) files, but you can pipe catdoc output into grep. I'm no programmer but this little script works well for me:
All improvements and suggestions welcome!
RalphRalph
I've just released a simple tool to do the job. Thought mainly for software developer, it has the (unique?) characteristic of openning several files in the same window. It presents the results in the browser using Ace editor (recomended!) or html textarea. It is a java based tool so it runs in windows as well as in linux.
check it out!
Alejadro XalabarderAlejadro Xalabarder