Find


Applies To: Windows Vista,Windows Server 2008

Searches for a string of text in a file or files, and displays lines of text that contain the specified string.

For examples of how to use this command, see Examples.

Syntax


Copy Code

find [/v] [/c] [/n] [/i] [/off[line]] "<String>" [[<Drive>:][<Path>]<FileName>[...]]

Parameters

Parameter

Description

/v

Displays all lines that do not contain the specified <String>.

/c

Counts the lines that contain the specified <String>and displays the total.

/n

Precedes each line with the file's line number.

/i

Specifies that the search is not case-sensitive.

[/off[line]]

Does not skip files that have the offline attribute set.

"<String>"

Required. Specifies the group of characters (enclosed in quotation marks) that you want to search for.

[<Drive>:][<Path>]<FileName>

Specifies the location and name of the file in which to search for the specified string.

/?

Displays help at the command prompt.

Remarks

Examples

To display all lines from Pencil.ad that contain the string "Pencil Sharpener", type:


Copy Code

find "Pencil Sharpener" pencil.ad

To find a string that contains text within quotation marks, you must enclose the entire string in quotation marks. Then you must use two quotation marks for each quotation mark contained within the string. To find "The scientists labeled their paper "for discussion only." It is not a final report." in Report.doc, type:


Copy Code

find "The scientists labeled their paper ""for discussion only."" It is not a final report." report.doc

If you want to search for a set of files, you can use the find command within the for command. To search the current directory for files that have the extension .bat and that contain the string "PROMPT", type:


Copy Code

for %f in (*.bat) do find "PROMPT" %f

To search your hard disk to find and display the file names on drive C that contain the string "CPU", use the pipe (|) to direct the output of the dir command to the find command as follows:


Copy Code

dir c:\ /s /b | find "CPU"

Because find searches are case-sensitive and dir produces uppercase output, you must either type the string "CPU" in uppercase letters or use the /i command-line option with find.

Additional references

Command-Line Syntax Key