System command

findstr command

Search files for matching text using literal or regular-expression patterns.

Availability: Microsoft Learn command reference spanning Windows client and Windows Server releases; some entries are legacy, role-specific, optional-feature or interactive subcommands.中文

Documented syntax

findstr [/b] [/e] [/l | /r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/f:<file>] [/c:<string>] [/g:<file>] [/d:<dirlist>] [/a:<colorattribute>] [/off[line]] <strings> [<drive>:][<path>]<filename>[ ...]

The linked Microsoft Learn article is the upstream authority. Availability may depend on Windows release, role, optional feature or interactive tool context.

Examples

Example usage for findstr.

findstr /s /n /i "error" *.log

Parameters, options and clauses

Option / clauseDescription
/iIgnore case when matching.
/nShow line numbers.
/sSearch the current directory and subdirectories.
/r, /lInterpret the pattern as a regular expression or literal text.
/v, /c:<text>Show non-matching lines or search for a literal string.
---Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/bMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
/eMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
/xMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
/mMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
/oMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
/pMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
/off[line]Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/f:<file>Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/c:<string>Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/g:<file>Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/d:<dirlist>Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/a:<colorattribute>Microsoft documents this switch; use the linked reference for accepted values, effects and version limits.
/offMicrosoft documents this switch; use the linked reference for accepted values, effects and version limits.
<strings>Microsoft documents this argument or subcommand; check the linked reference for its required format and context.
<drive>Microsoft documents this argument or subcommand; check the linked reference for its required format and context.
<path>Microsoft documents this argument or subcommand; check the linked reference for its required format and context.
<filename>Microsoft documents this argument or subcommand; check the linked reference for its required format and context.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory