Whether you’re auditing source code, debugging config issues, or searching logs, Linux offers powerful tools to search files by their content—not just by name. With the right command-line utilities, you can find exact strings, patterns, or even multiline matches across thousands of files in seconds.
This advanced guide dives into how to search for files containing specific content in Linux, using tools like:
grep
, find
, ack
, ripgrep
Let’s simulate a working directory with config files.
grep -r "password" ~/test-config
. = current directory
-type f = only files
-exec grep -l “password” {} + = run grep on the files and show only those that contain “password”.
Example: Find all .conf files under /etc/ that contain “max_connections”
find . -name "*.conf" -exec grep -Hn "max_connections" {} +
find . — searches from current directory
-name “*.conf” — only targets .conf files
-exec grep -Hn — searches for the string max_connections
-H prints filename
-n prints line number
Ignores .git, node_modules, vendor/, etc.
Supports regex and file type filters
Faster and cleaner than grep in dev environments
Install ack (if not already installed)
sudo apt install ack-grep # Debian/Ubuntu
brew install ack # macOS
ack "connectDB" ~/test-code
Ultra-fast (written in Rust)
Recursive by default
Syntax highlighting
Git-aware (skips .gitignored files)
Some system files require elevated permissions:
Or when combining with find:
2>/dev/null: suppresses permission errors
Combine: grep -rwi “word”
✅ Avoid binary files:
✅ Limit depth:
✅ Log file search with date:
Example – extract matched line + 2 lines after:
Or use awk to extract patterns:
Searching files by content is one of the most essential skills for any Linux user or developer. From simple grep commands to powerful tools like ripgrep, you can quickly pinpoint information hidden in thousands of files.
Mastering these tools means faster debugging, safer audits, and more efficient workflows.