15.04.2025

How to Find Text in Files on Linux and Windows: grep, Notepad++, and findstr

How to Find Files Containing Specific Text in Linux and Windows

Searching for specific text within files is a common task when working with codebases, log files, or documentation. While Linux systems offer powerful command-line tools like grep out of the box, Windows systems require additional tools to perform similar tasks. This guide will walk you through effective ways to find files that contain defined text on both platforms.

The most widely used Linux shell is Bash, which provides a robust command-line interface (CLI). Before graphical environments became common, CLI was the primary way to interact with Unix-like systems, which led to the development of extremely capable command-line tools.

One such tool is grep, a built-in utility in almost all modern Linux distributions. It allows you to search recursively for a specific string inside files within a directory.

Installing grep

In most cases, grep is already installed. But if it’s missing, you can install it using the following commands:

For Debian/Ubuntu-based systems:

apt update && apt install grep -y

For RHEL/CentOS-based systems:

yum install grep -y

Searching for Text in Files

To search for a specific string within files in a given directory, use:

grep -r "search_string" /path/to/search/

Explanation of flags:

Example:

grep -rsn "error 404" /var/log/

This command will look through all files in /var/log, displaying the filename, line number, and the line that contains the string "error 404".

How to do text research on Windows computer

Unfortunately, Windows does not include a powerful CLI text search utility like grep by default. However, you can work around this in a few ways:

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:

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

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

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

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:

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:

 

Result is below:

FAQ

grep -i "warning" logfile.txt
grep -r --binary-files=without-match "text"
find . -name "*.log" -exec grep -nH "text" {} +

Conclusion

In this article, we explored practical and effective methods for locating specific text within files on both Linux and Windows operating systems. Mastering text search techniques is an essential skill for developers, system administrators, DevOps engineers, and anyone who works with large file systems, source code, or log files.

On Linux, we focused on the powerful and widely available grep utility. It's built into nearly every Linux distribution and provides flexible options for recursive search, line numbering, case-insensitive matching, error suppression, and more. With just a few flags, grep becomes an indispensable tool for quickly scanning through files and directories — whether you're searching for a bug trace, a configuration directive, or user activity logs.

On Windows, where similar functionality is not available by default, we covered two reliable alternatives:

These tools allow users to:

Regardless of the operating system you work on, knowing how to search through files effectively will significantly boost your productivity and troubleshooting capabilities. Instead of relying on manual inspection or guesswork, you can now pinpoint exact lines of interest in seconds — even in projects with thousands of files.

By understanding and applying the techniques covered here, you are well-equipped to handle text searching tasks with confidence and precision across platforms.

Pro Tips for Efficient Text Search

Whether you're dealing with massive codebases, system logs, or scattered configuration files, these advanced techniques can make your search much faster and more precise:

1. Use Regular Expressions

Regular expressions (regex) allow you to search for complex patterns rather than exact text. Both grep and Windows tools support this:

Tip: Test your regex on a site like regex101.com to avoid mistakes.

2. Search Only Specific File Types

If you're working in a project folder with many files, you might want to target specific extensions:

3. Use ripgrep for Blazing Speed

ripgrep (rg) is a faster and smarter alternative to grep. It respects .gitignore, supports regex, and works great for large projects:

rg "function.*init" ./src

You can install it on Linux via:

sudo apt install ripgrep

Or on Windows via scoop or chocolatey.

4. Filter by File Size or Age

Use find together with grep for more control:

find /var/log -type f -size +5M -exec grep "OutOfMemory" {} \;

This finds only files larger than 5 MB and searches within them.

5. Search Without Case Sensitivity

Sometimes errors or config keys use different cases. You can ignore case with:

grep -i "hostname" /etc/hosts

Or in Windows:

findstr /I "hostname" hosts.txt

6. Preview Large Files While Searching

For huge files, combine tools:

less +/search_term bigfile.log

This opens the file with the cursor already on the matched text.

7. Combine with awk or sed for Contextual Output

Need lines before or after a match?

grep -C 3 "panic" /var/log/syslog # 3 lines of context

Or use awk for even more custom output:

awk '/panic/{print NR, $0}' /var/log/syslog