# grep tutorial

`grep` = **search text** inside files or command outputs.

## **1\. Basic Search**

```bash
grep "text" filename
```

Searches for `"text"` inside `filename`.

---

## **2\. Search in All Files (Recursive)**

```bash
grep -r "text" .
```

Search from current directory into subfolders.

---

## **3\. Case-Insensitive Search**

```bash
grep -i "text" file
```

---

## **4\. Show Line Numbers**

```bash
grep -n "text" file
```

---

## **5\. Search Whole Word Only**

```bash
grep -w "word" file
```

---

## **6\. Show Only the Matching Part**

```bash
grep -o "pattern" file
```

---

## **7\. Count Matches**

```bash
grep -c "text" file
```

---

## **8\. Use Regex**

Find lines starting with “hello”:

```bash
grep "^hello" file
```

Ending with “world”:

```bash
grep "world$" file
```

---

## **9\. Search Multiple Files**

```bash
grep "text" *.txt
```

---

## **10\. Invert Match (show lines NOT containing pattern)**

```bash
grep -v "text" file
```

---

## **11\. Pipe with Other Commands**

Check running processes containing “python”:

```bash
ps aux | grep python
```

---

## **12\. Highlight Matches**

```bash
grep --color=auto "text" file
```
