10/23/2020 Mac Search For Files Containing Text
You can search your entire system for containing text and you can also specify parameters like file size and date modified. It has an incredibly simple and easy to use interface, which is quite possibly easier to navigate than the actual Windows search. Beneath each file is a collapsible list of the lines within the file that contain the search text, preceded by the line number where it occurs. If you cannot see the entire line, hover your mouse over it, and a tooltip will open displaying the entire line's contents. Always search file names and contents (NB: will be a slower search) Open a Windows Explorer window Alternatively, you could add the location to your indexed locations.
Active2 years, 3 months ago
I'd like to find all files that contain a certain string of text. How would you do that in the Terminal?
Chealion
22.6k77 gold badges6161 silver badges7171 bronze badges
Svish
![]()
17.9k5555 gold badges112112 silver badges170170 bronze badges
5 AnswersIgnacio Vazquez-AbramsIgnacio Vazquez-Abrams
98.7k77 gold badges162162 silver badges217217 bronze badges
user46046user46046
brew install ack ack 'text goes here'
find . |grep 'text goes here'
grep -RnslI 'text goes here'
Anant GuptaAnant Gupta
You can choose one of the below depending on your taste and needs. Supposing you need to search for files containing text - 'async', recursively in current directory, you can do so in one of the ways like below:
Using grep
Search For Files In Windows 7
Using ack
karthikskarthiks
Ignacio's Answer is great and helped me find the files containing certain text. The only issue I was facing was that when running this command all the files would be listed, including one where the pattern did not show up.
![]() Mac Terminal Find Files Containing TextNo such file or directory This is what I see alongside files that do not contain the pattern.
If instead you add
-s to the command, as in:grep -lr 'text pattern' ./ -s ; grep -lr 'text pattern' [PATH DIRECTORY] -s is used, it will only show you which files contain the pattern.
Similarly if
grep -nr 'text pattern' ./ -s ; grep -nr 'text pattern' [PATH OF DIRECTORY] -s command is used it prints the file plus the line number, and occurrence of the pattern.
Please correct me if my understanding is wrong.
CP3OCP3O
Not the answer you're looking for? Browse other questions tagged macosmacunixterminalsearch or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |