Serverspace Black Friday
VB
February 2 2023
Updated December 6 2024

How to find files which contains defined text in Linux and Windows

Linux

How to find files which contains defined text in Linux

The most popular Linux command interpreter is bash. Historically, Linux have had CLI-interface only, graphical environment has been integrated later. It is a reason why we have much possibilities to effective data-manipulation via CLI-interpreter. The best way to find files with required text string in Linux is grep utility. It is built-in tool in all modern Linux operation systems. Most probably that you don't need to install it cause it is exist. But even if not -  you can install this tool anyway.

Command to install in Debian-based OS (like Ubuntu) is:

 apt-get update && apt install grep 

Command to install in RedHat-based OS (like Centos) is:

yum install grep

To find all files with required string just run:

grep -r <looked_for_text> <dir>

pic1

To avoid errors message in the output you may add -s flag to the command:

pic2

And the last but not least useful flag is -n. This option shows line with out text. It may me useful for large files:

pic3

 

How to do text research on Windows computer

Unfortunately, Windows doesn't have good searching tools "out-of-the-box" but we have some quick'n'easy ways to fix it.

First way is grep utility. It has been "ported" on Windows OS, so you can install it:

Download installer here, run it and follow standard Windows-like installation steps:

pic4

pic5

pic6

pic7

When program installed, you should add environment variable to make furher life more comfortable. Just open advanced PC options and edit PATH variable:

pic8

Add new option into PATH variable according to the your installation folder:

pic9

Then you can run cmd interpreter and do searching. Program syntax is identical to "original" Linux tool:

pic10

NOTE: Cause this tool is a Linux port, system root is shown in Linux-style, "slash" instead of C: drive.

 

Other, more "Windows-like" method is install powerful text editor e.g. Notepad++. Download it from project site, run the app and install it as usual:

pic11

pic12

pic13

To use this app as "text-finder" just run it and choose Search > Find in Files command. Then fill into the appropriate fields searching conditions:

pic14

 

Result is below:

pic16

Conclusion

In this article I discribed some ways how to make powerful text search in Linux and Windows.

 

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.