Command to Search for Words: grep, findstr, Select-String and an Easier Offline Alternative
Short answer: The command to search for words inside files is grep on macOS and Linux (for example grep -rni "invoice" ~/Documents), findstr in the Windows Command Prompt (findstr /s /i "invoice" *.txt), and Select-String in PowerShell. All three match exact text and work best on plain-text files, not PDFs or Word documents.
Free to try (1 folder, 200 files) · US$14.99 to keep · Mac & Windows
You know a word or phrase is in one of your files. You just don't know which file. The command line is a fast, free way to check, and every Windows, Mac and Linux computer already has a tool built in for it.
This guide gives you the exact command to search for words on each system, with copy-ready examples. It also explains where these commands fall short, especially with PDFs, Word documents and scanned pages, and what to use when you remember the idea of a document but not its exact wording.
The Windows command to search for words: findstr
In the Windows Command Prompt, the command to search for words inside files is findstr. Open Command Prompt, move into the folder you want to search with cd, and run:
findstr /i "invoice" *.txtsearches all .txt files in the current folder, ignoring case.findstr /s /i /n "invoice" *.txtadds subfolders (/s) and shows line numbers (/n).findstr /s /i /m "invoice" .lists only the names of matching files (/m), which is often all you need.findstr /s /i /c:"payment terms" *.txtsearches for the exact phrase.
That last flag matters. Without /c:, findstr treats spaces as OR, so findstr "payment terms" returns lines containing either word. To require two words on the same line, chain searches: findstr /i "budget" notes.txt | findstr /i "forecast".
findstr is quick and always available, but it is old and basic. Its regular-expression support is limited, and it reads files as raw text.
PowerShell Select-String: a more flexible search command
In PowerShell, Select-String is the more capable equivalent of findstr and of grep. It is case-insensitive by default and supports full regular expressions.
Select-String -Path *.txt -Pattern "invoice"searches text files in the current folder.Get-ChildItem -Recurse -Include .txt,.md,*.csv | Select-String -Pattern "invoice"searches every matching file in all subfolders.- Add
-Listto stop at the first match per file, then| Select-Object Pathto print just file paths. - Use
-SimpleMatchto search for literal text (so characters like.or?are not treated as regex), and-CaseSensitivewhen case matters. -Pattern "budget","forecast"matches lines containing either word.
Select-String output includes the file name, line number and matching line, which makes it easy to scan results. Like findstr, though, it reads files as text, so it shares the same blind spots with documents.
grep on Mac and Linux (and mdfind on a Mac)
On macOS and Linux, the standard command to search for words in files is grep. Open Terminal and try:
grep -rni "invoice" ~/Documentssearches recursively (-r), shows line numbers (-n) and ignores case (-i).grep -rl "invoice" .lists only matching file names (-l).grep -rw "tax" .matches whole words only, so "tax" won't match "taxonomy".grep -rF "$1,200.00" .searches for a fixed string with no regex interpretation.grep -rE "budget|forecast" --include="*.md" .finds either word, limited to Markdown files.
mdfind: grep's document-aware cousin on macOS
Macs also have mdfind, the command-line front end to Spotlight. mdfind -onlyin ~/Documents "quarterly review" searches the Spotlight index rather than raw bytes. Because Spotlight indexes files and their content, mdfind can often find words inside PDFs and Word files that grep misses. Windows has a similar index behind File Explorer search, and Windows Search indexing can be configured to include file contents, though it is not exposed through findstr.
Why search commands miss PDFs, Word docs and scans
grep, findstr and Select-String read the raw bytes of a file, so they only work reliably when the words are stored as plain text.
That breaks down with common document formats:
- Word (.docx) files are compressed ZIP archives of XML. The words are not stored as readable text, so a plain grep usually finds nothing. Older .doc files are binary and hit-or-miss.
- PDFs usually store text in compressed streams, sometimes split into fragments. A search can miss a phrase even when you can see it on the page. See our guide on how to search a PDF for a word or idea.
- Scanned PDFs and images contain pictures of text, not text. Nothing can match until OCR converts them, which these commands don't do.
- Excel and PowerPoint files have the same compressed-XML problem as Word.
There is a second, quieter limit: exact matching. If the contract says "termination for convenience" and you search "cancel the agreement", no keyword tool will connect them. You have to guess the author's exact words. That is the core difference covered in semantic search vs keyword search.
Workarounds exist, such as converting files to text first or using document-specific tools, but they add steps and still leave you guessing at wording.
Which search method to use when
Use command-line tools for plain-text files and exact strings, and a document-aware or meaning-based tool for PDFs, Office files and scans.
| Method | Platform | Reads PDF/Word? | Matches by | Scanned pages |
|---|---|---|---|---|
| findstr | Windows (cmd) | No | Exact text | No |
| Select-String | Windows (PowerShell) | No | Text or regex | No |
| grep | Mac, Linux | No | Text or regex | No |
| mdfind | Mac | Often, via Spotlight | Keywords | Varies |
| Fossick | Windows, Mac | Yes | Meaning | Yes, on-device OCR |
If you are searching log files, code, CSVs or notes in Markdown, grep or Select-String is hard to beat. If your files are mostly contracts, reports and scanned letters, the command line will keep coming up empty.
An offline alternative that searches by meaning
If you want to find documents by what they say rather than their exact words, an on-device semantic search app does that without uploading anything.
Fossick is a desktop app for Windows and Mac that searches your local documents by meaning, entirely offline. You point it at a folder, it indexes the contents, and then you type what you remember, such as "the letter about late delivery penalties", to find the matching documents. Semantic search aims to match the meaning of a query rather than its exact keywords, which is exactly the gap grep and findstr leave.
What it handles that the commands don't:
- Real document formats: PDF, Word (.docx, .doc), Excel, PowerPoint, OpenDocument text, plain text, Markdown, CSV, HTML, and email (.eml, .msg).
- Scanned PDFs and images: PNG and JPG files and scanned pages are made searchable with on-device OCR. More in how to search scanned PDFs locally.
- Speed after indexing: about 15-20 ms median per search over a 52-document folder on an 8 GB Apple M1 MacBook. Re-indexing is incremental, so only new or changed files are re-processed.
What stays on your computer
Text extraction, OCR, embedding and search all run on your device using a small local model (all-MiniLM-L6-v2, about 22 MB). Documents are never uploaded, and it works with Wi-Fi off; only licensing touches the internet. That matters if your files are confidential.
It is also worth being clear about what it is not: Fossick is search, not chat. There is no chatbot, no generative AI and no summaries. It returns your documents; you read them.
You can download it and try it free with no sign-up or card on 1 folder of up to 200 files. The full app is a one-time US$14.99 purchase with all future updates and a 14-day money-back guarantee; see pricing. Keep grep and Select-String for text files and exact strings, and use meaning-based search for everything else.
Frequently asked questions
How do I search for an exact phrase with grep or findstr?
With grep, wrap the phrase in quotes: grep -rni "payment terms" .. With findstr, use the /c: flag, as in findstr /s /i /c:"payment terms" *.txt, because without it findstr treats each space-separated word as an alternative.
How do I search for multiple words at once from the command line?
For either word, use grep -E "budget|forecast" on Mac or Linux, findstr "budget forecast" in Command Prompt, or Select-String -Pattern "budget","forecast" in PowerShell. To require both words on the same line, pipe one search into another, for example grep -i budget file.txt | grep -i forecast.
Can findstr or grep search inside Word documents and PDFs?
Not reliably. Word .docx files are compressed archives and most PDFs store text in compressed streams, so raw-text tools usually miss the words. On a Mac, mdfind uses the Spotlight index and often works better; for scanned files you need a tool that runs OCR.
Is there a way to search my documents by meaning without uploading them?
Yes. On-device semantic search apps index your files locally and compare meaning on your own computer. Fossick, for example, runs extraction, OCR, embedding and search entirely on your device and works with Wi-Fi off, so documents never leave your machine.