---
tags:
  - macOS
  - Tahoe
  - grep
  - terminal
  - search
title: Searching Text with Grep on macOS Tahoe
---

# Searching Text with Grep on macOS Tahoe

`grep` (Global Regular Expression Print) is a powerful command-line utility used to search for specific patterns of text within files. On macOS Tahoe, it is an essential tool for filtering logs, finding code snippets, and searching through configuration files.

## Basic Usage

The basic syntax for `grep` is:

```zsh
grep "search_term" filename
```

**Example:**
To find the word "error" in a file named `app.log`:

```zsh
grep "error" app.log
```

## Common Flags

`grep` becomes much more powerful when you use flags to modify its behavior.

### Case Insensitive Search (`-i`)
By default, `grep` is case-sensitive. Use `-i` to ignore case.

```zsh
grep -i "error" app.log
```
This will match "Error", "ERROR", and "error".

### Recursive Search (`-r`)
To search through all files in a directory and its subdirectories, use `-r`.

```zsh
grep -r "function_name" ~/Projects/my-app/
```

### Show Line Numbers (`-n`)
To see exactly where the match occurred, use `-n`.

```zsh
grep -n "TODO" main.py
```
Output: `42: # TODO: Fix this bug`

### Invert Match (`-v`)
Sometimes you want to see everything *except* the pattern.

```zsh
grep -v "DEBUG" app.log
```
This prints all lines that do *not* contain "DEBUG".

## Using Grep with Pipes

One of the most common ways to use `grep` on macOS is by piping the output of another command into it.

### Filtering Process List
To check if a specific app is running:

```zsh
ps aux | grep "Chrome"
```

### Filtering History
To find a command you ran previously:

```zsh
history | grep "git commit"
```

## Regular Expressions

`grep` supports Regular Expressions (Regex) for advanced pattern matching.

*   `^`: Matches the start of a line.
*   `$`: Matches the end of a line.
*   `.`: Matches any single character.

**Example:**
Find lines that start with "Error":

```zsh
grep "^Error" app.log
```

For more on general terminal usage, refer to Getting Started with macOS Tahoe.