Linux Tutorial — Part 6: Searching Text & Filtering Data

In this part, we learn one of the most powerful Linux skills — searching text inside files and command output. This is where Linux becomes dangerous (in a good way).

1. grep — Search Text Inside Files

grep searches for matching text patterns. It is used everywhere: logs, configs, scripts, pipelines.

grep "error" file.txt

This prints all lines containing the word error.

2. Case-Insensitive Search

Linux is case-sensitive by default. Use -i to ignore case.

grep -i "error" file.txt

3. Search in Multiple Files

grep "failed" *.log

This searches across all log files.

4. Recursive Search (Folders)

Search inside directories using -r.

grep -r "password" /etc

⚠️ Warning

Recursive grep can be heavy. Use it carefully on large directories.

5. grep with Line Numbers

grep -n "listen" nginx.conf

Shows exact line number — critical for debugging.

6. Pipes (|) — The Linux Superpower

Pipes send output of one command into another.

ls -l | grep ".log"

This filters only log files from directory listing.

7. grep with ps (Process Search)

Find running processes:

ps aux | grep nginx

8. Excluding Matches

Use -v to exclude matching lines.

ps aux | grep -v grep

9. Real-World Log Example

grep -i "error" /var/log/syslog

System admins live inside commands like this.

Important Mindset

Linux tools are simple alone, unstoppable when combined.

If you master grep and pipes, you control text — and Linux is mostly text.

In the next part, we will learn about file permissions and ownership — the most misunderstood Linux concept.

Next: File Permissions & Ownership →
Disclaimer:
Some files require root access. Always understand what you are searching before using sudo.