Searching Parameters. You can specify the File Name in a Simple mode or using Wildcards. You can find Words or Phrases inside Plain Text Files or Encoded Documents using the Text Filters built-in with the Software or the IFilters. You can also search by Date and Size, Files and Folders Attributes and by Filename, Folder, or Full Path Lengths.
Active7 years, 8 months ago
I want to find some text inside binary files. Is it possible to do in Finder (it skips binary even if I set up 'All kinds' of file types)? Otherwise I would be thankful for utility that can do it.
PS: I need to search among many files in directory.
brigadirbrigadir
3 Answers
You should use the
strings
application in the Terminal.From Wikipedia:
In computer software, strings is a program in Unix-like operating systems that finds and prints text strings embedded in binary files such as executables.
I'm not aware of any way to use Finder to search for text in binary files.
michaelmichaelmichaelmichael2,96311 gold badge1919 silver badges2424 bronze badges
After some digging on Google I found EasyFind.app. This app can search in selected or all file types.
brigadirbrigadir
garygary
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.
You must log in to answer this question.
Not the answer you're looking for? Browse other questions tagged macsearch .
Active3 months ago
In the linux shell, the following command will recursively search and replace all instances of 'this' with 'that' (I don't have a Linux shell in front of me, but it should do).
What will a similar command on OSX look like?
George Stocker♦46.8k2929 gold badges158158 silver badges223223 bronze badges
JackJack9,6381313 gold badges7979 silver badges148148 bronze badges
14 Answers
OS X uses a mix of BSD and GNU tools, so best always check the documentation (although I had it that
less
didn't even conform to the OS X manpage): sed takes the argument after
-i
as the extension for backups. Provide an empty string (-i '
) for no backups.The following should do:
LC_ALL=C find . -type f -name '*.txt' -exec sed -i ' s/this/that/ {} +
The
vitaut-type f
is just good practice; sed will complain if you give it a directory or so.-exec
is preferred over xargs
; you needn't bother with -print0
or anything.The {} +
at the end means that find
will append all results as arguments to one instance of the called command, instead of re-running it for each result. (One exception is when the maximal number of command-line arguments allowed by the OS is breached; in that case find
will run more than one instance.)24.1k1515 gold badges9696 silver badges164164 bronze badges
TaylanUBTaylanUB3,65011 gold badge1212 silver badges1515 bronze badges
For the mac, a more similar approach would be this:
WillWill1,87011 gold badge1515 silver badges2020 bronze badges
madxmadx4,35433 gold badges3838 silver badges4848 bronze badges
As an alternative solution, I'm using this one on Mac OSX 10.7.5
Credit goes to: Todd Cesere's answer
Maciej GurbanMaciej Gurban4,91933 gold badges2424 silver badges4545 bronze badges
eb80eb802,81944 gold badges1818 silver badges2828 bronze badges
A version that works on both Linux and Mac OS X (by adding the
-e
switch to sed
):vrocvroc
This is my workable one. on mac OS X 10.10.4
The above ones use find will change the files that do not contain the search text (add a new line at the file end), which is verbose.
NoteCodeNoteCode
If you are using a zsh terminal you're able to use wildcard magic:
sed -i ' 's/search/high-replace/g' *.txt
MentorMentor
Whenever I type this command I always seem to hose it up, or forget a flag. I created a Gist on github based off of TaylanUB's answer that does a global find replace from the current directory. This is Mac OSX specific.
It's nice because now I just pop open a terminal then copy in:
curl -s https://gist.github.com/nateflink/9056302/raw/findreplaceosx.sh | bash -s 'find-a-url.com' 'replace-a-url.com'
You can get some weird byte sequence errors, so here is the full code:
Nate FlinkNate Flink3,49922 gold badges2525 silver badges1818 bronze badges
https://bitbucket.org/masonicboom/serp is a go utility (i.e. cross-platform), tested on OSX, that does recursive search-and-replace for text in files within a given directory, and confirms each replacement. It's new, so might be buggy.
![Search Search](https://static.makeuseof.com/wp-content/uploads/2018/11/05-Text-file-from-Linux-in-Notepad.png)
Usage looks like:
user4425237user4425237
user2725109user272510996422 gold badges1717 silver badges3535 bronze badges
I used this format - but...I found I had to run it three or more times to get it to actually change every instance which I found extremely strange. Running it once would change some in each file but not all. Running exactly the same string two-four times would catch all instances.
user1399145user1399145
The command on OSX should be exactly the same as it is Unix under the pretty UI.
clopsclops2,64666 gold badges3232 silver badges4949 bronze badges
Samuel DevlinSamuel Devlin
protected by eyllanescSep 6 '18 at 1:43
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?