> For the complete documentation index, see [llms.txt](https://notes.programmersecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.programmersecurity.com/ctfs/grep-and-regex-and-find-strings.md).

# Grep & Regex & Find strings

## Grep To find Files and Strings

We can use GREP to find some keywords and files and some special strings

<pre class="language-python"><code class="lang-python">grep -inr password

<strong>i is for case insensitivity
</strong>n is for line number
r is for recursively

this command will recursively search for the keyword password 
</code></pre>

## Grep to find strings using Regex

lets say we have a file with a certain line

<figure><img src="/files/ihcJATddSU3J7tXcal6L" alt=""><figcaption></figcaption></figure>

now i need to find in how many files this line exists, so i can use regex with grep

```python
grep -rnw $(pwd) -e "^.*user_location.*public.*" --color


$(pwd)- means your current working directory in which you want to find
        otherwise give the complete path of the directory here
        
this command will find you the all files having above line 
```

## Egrep to do Advanced Regex

We can use egrep for more advanced regular expressions, below is the egrep command with more advacned regex which finds for $addslahses keyword and whatever is after that.

```
egrep '\$addslashes.*=.*' $(pwd) -r --color
```

## Find Command

```
find / -iname "*.html"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://notes.programmersecurity.com/ctfs/grep-and-regex-and-find-strings.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.
