# Grep (Searching Pattern)

```bash
#!/bin/bash

# Define the word to search for
SEARCH_WORD="your_word"

# Basic Recursive Search:
# Searches for the specified word in all files within the current directory and its subdirectories.
grep -r "$SEARCH_WORD" .

# Recursive Search with Line Numbers:
# Similar to the above, but includes the line numbers where the word is found.
grep -rn "$SEARCH_WORD" .

# List Only Filenames with Matches:
# Displays only the filenames of the files that contain the specified word, without showing the lines.
grep -rl "$SEARCH_WORD" .

# Case-Insensitive Search:
# Searches for the word without considering case (e.g., "Word", "word", "WORD" will all match).
grep -rin "$SEARCH_WORD" .

# Search Specific File Types (e.g., .txt files):
# Limits the search to files with a specific extension or pattern.
grep -rn --include=\*.txt "$SEARCH_WORD" .

# Exclude Specific Directories:
# Excludes certain directories from the search (e.g., 'dir_to_exclude').
grep -rn "$SEARCH_WORD" . --exclude-dir='dir_to_exclude'

# Combined Example:
# A case-insensitive search for the word in all .txt files, excluding a specific directory.
grep -rin --include=\*.txt "$SEARCH_WORD" . --exclude-dir='dir_to_exclude'

```

```
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://n0m4dsec.gitbook.io/sec-book/some-important-linux-commands/grep-searching-pattern.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
