How to search inside files

Overview

findstr prints lines that match text or a pattern. It can search files directly or filter output received through a pipe.

Start with literal, case-insensitive searches. Regular-expression metacharacters can change a search unexpectedly.

  • /c:"phrase here" treats a spaced phrase as one search string.
  • A successful match is printed; no output often means no match.
  • By default, multiple space-separated search words are alternatives.

Commands to try

Type each command at the prompt, then press Enter. Replace sample names and paths with ones that exist on your computer.

Commands are generally not case-sensitive, but preserving the spelling shown here makes scripts easier to read.

findstr /i "error" app.log
findstr /n /i /c:"access denied" *.log
findstr /s /i /m "TODO" *.txt
tasklist | findstr /i "chrome"

Useful options and details

Options change how a command behaves. Add spaces exactly as shown, and use the command's built-in help when an option is unfamiliar.

A path containing spaces must be enclosed in double quotes, such as "C:\My Files".

  • /i ignores case and /n shows line numbers.
  • /s searches subfolders and /m prints only matching filenames.
  • /l forces literal strings; /r selects regular expressions.

Tips and common mistakes

Check the current folder and read the command output before assuming an operation succeeded.

Practice with disposable files first. Commands that delete, overwrite, or stop a process may not offer an Undo button.

  • FINDSTR regular expressions are limited and differ from many programming languages.
  • Binary or differently encoded files may not search correctly.
  • Quote paths and use /c: for exact phrases with spaces.

Safe practice

Create a temporary practice folder under your user profile so the examples cannot affect Windows system files.

After each command, inspect the result with dir or another read-only command before continuing.

  • Create a small log with mixed-case status words.
  • Search it case-insensitively with line numbers.
  • Pipe dir into findstr to filter names.