Skip to content
New — orchestrate a team of Mel agents from your terminal. Learn more about orchestrating Mel agents
← All guides

Guides · terminal

How to search for text in files from the terminal

By Lalla Asmaa Alaoui, founder of Mel · Updated

On Mac and Linux, grep -rn "text" . searches every file below the current folder and prints each match with its file name and line number. On Windows, findstr /s /n "text" * does the same in Command Prompt, and Select-String does it in PowerShell.

Once you know a few flags, you can narrow a search to one file type, ignore case, skip folders like node_modules, or list only the files that match. The steps below go from the basic search to the faster tools many developers use.

Mac and Linux with grep

  1. Search everything below this folder.
grep -rn "TODO" .

-r searches folders recursively, -n adds line numbers, and . means "start here". Quote the text so the shell does not change it.

  1. Ignore upper and lower case.
grep -rni "timeout" .
  1. Match whole words only. -w stops log from matching login or catalog.
grep -rnw "log" .
  1. Search one kind of file.
grep -rn --include="*.py" "def main" .

You can repeat --include for more types, such as --include="*.js" --include="*.ts".

  1. Skip folders you do not care about.
grep -rn --exclude-dir=node_modules --exclude-dir=.git "apiKey" .
  1. List only the file names.
grep -rl "deprecated" .

Add -c instead of -l to count matches per file.

  1. Use a pattern. -E turns on extended regular expressions:
grep -rnE "version[ =:]+[0-9]+" .
  1. Show context. -C 2 prints two lines before and after each match, which often answers the question without opening the file.
grep -rn -C 2 "throw new Error" src

Faster: ripgrep and git grep

  1. ripgrep (rg). If you have it installed, it is quick and skips files listed in .gitignore by default.
rg -n "TODO"
rg -n -t py "def main"
  1. git grep. Inside a git repository, it searches tracked files only and is built into git.
git grep -n "TODO"

Both work on Mac, Linux and Windows.

Windows

  1. Command Prompt with findstr.
findstr /s /n /i "timeout" *.js

/s searches subfolders, /n adds line numbers and /i ignores case. Note that findstr treats spaces in the search text as "or" by default. To search for an exact phrase, use /c::

findstr /s /n /c:"connection refused" *.log
  1. PowerShell with Select-String.
Get-ChildItem -Recurse -File -Include *.js, *.ts |
  Select-String -Pattern "timeout"

Each result shows the path, line number and line. Add -CaseSensitive if case matters; by default it ignores case. Add -SimpleMatch to search for the text exactly instead of as a pattern.

Doing it with Mel

Mel runs your own shell, so every command above works at its prompt. Results land in a block, and file paths in the output become links: ctrl+click (cmd+click on macOS) to open one. You can filter a long block of results down to the lines you want.

Mel also has a built-in global search. Press ctrl+shift+F and type. It uses ripgrep when it is installed and falls back to git grep when it is not. Two toggles in the field switch on case-sensitive matching (Aa) and regular expressions (.*). Results are grouped per file, and clicking a hit opens the file at that line in Mel's editor, beside your terminal. The search runs on your machine and sends nothing anywhere.

When you are not sure what to search for, ask the agent. Press ctrl+enter (cmd+enter on macOS) and write something like "where is the login timeout set in this project?". The agent has its own search tool for your project, and reading and searching run without an approval card because they change nothing.

FAQ

How do I search for text in all files in a folder? Run grep -rn "text" . on Mac and Linux. On Windows, run findstr /s /n "text" * in Command Prompt.

How do I make grep ignore case? Add -i, for example grep -rni "text" ..

How do I exclude node_modules from grep? Add --exclude-dir=node_modules. ripgrep and git grep usually skip it already, because it is in .gitignore or not tracked.

How do I find files by name rather than by content? Use find . -name "*report*" on Mac and Linux, or Get-ChildItem -Recurse -Filter *report* in PowerShell.

What is the difference between grep and ripgrep? Both search file contents. ripgrep is a separate tool that is usually faster and respects .gitignore by default. grep comes with Mac and Linux.

Mel – the agentic terminal · openmel.dev. A multi-agent, multi-model AI terminal for Mac, Windows, Linux and VS Code. Free with your own API key.

Lalla Asmaa Alaoui
Written by
Lalla Asmaa Alaoui
Founder & CEO of Mel

Lalla is a hands-on tech founder, agentic infrastructure architect and the vision behind Mel.

Follow on LinkedIn

Get started

Try the agentic terminal.

The Mel terminal is free to download, no account needed. The AI agent is free on your own provider key — 1,500 hosted-AI credits a month on Pro.