Find

Index

The FIND command is used to search for a text string in a file or files. After searching the specified files, FIND displays any lines of text that contain the string.

Syntax:

FIND [/V] [/C] [/N] [/I] "string" "filename1" "filename2" "filename ..."

/VDisplays all lines NOT containing the specified string.
/CDisplays only a count of lines containing the string.
If used with /V, FIND displays a count of the lines that do not contain the specified string.
/NDisplays line numbers with the lines. If /C and /N are used together, /N is ignored.
/IIgnores the case of characters in string. By default FIND is case sensitive and searches for an exact character match.
stringThe text string to be found. String must be in inverted commas.
filenameThe file(s) to be searched. If filename does not contain spaces, it does not need to be enclosed in inverted commas.

Notes:

If filename is not specified, FIND searches the text input from the "standard" source (usually the keyboard), a pipe, or a redirected file.

Wildcards (* and ?) are not accepted in filename. However, to search for string in a set of files, it is often possible to use the FIND command within a FOR loop structure.

If a DIR command output is piped to FIND, a list of files/directories whose names contain string will be displayed. There is no straightforward way to use DIR to make a list of files within which FIND will search for string.

Because inverted commas are used to delimit string, they cannot be used within string as part of the search pattern. To include inverted commas within string, it is necessary to use the "special character" of double inverted commas ("") which FIND interprets as inverted commas in the search string.

The FIND command does not accept carriage returns in the search string - nor will it recognize a string that has a carriage return embedded in it. For example, FIND does not report a match for the string "tax file" if "tax" and "file" happen to be on different lines because of word wrapping.

Exit Codes:

0The search was completed successfully and at least one match was found.
1The search was completed successfully, but no matches were found.
2The search was not completed successfully. In this case, an error occurred during the search, and FIND cannot report whether any matches were found.

Examples:

To display all lines from the file "pencil.ad" that contain the string "Pencil Sharpener":
FIND "Pencil Sharpener" pencil.ad

If the string contains quotation marks, these must be doubled:
FIND "This paper is ""for discussion only."" It is not a final report." report.doc

To search the current directory for the string "PROMPT" in all .BAT files:
FOR %f in (*.bat) DO FIND "PROMPT" %f

To search your hard disk to find and display the filenames on drive C that contain the string "CPU", you can use the pipe "|" to direct the results of a DIR command to FIND:
DIR c:\ /s /b | FIND "CPU"
Remember, the default output from DIR can be upper and/or lower case depending on how a file was saved. To catch all instances of "CPU", "cpu". etc. either use the /L switch with DIR (to force lower case output), or the /I switch with FIND (to ignore case in string).

File Details

File NameDefault LocationDos Ver.Win Ver.SizeDateSource
Find.exec:\windows\command 7.0Win95 6 658111/07/95win95_08.cab
7.1Win95 (OSR2.x) 6 658224/08/96win95_14.cab
Win98 6 658211/05/98win98_41.cab
Win98 SE 6 658223/04/99win98_45.cab

Superscripts denote which same size files, if any, are identical (using FC).


This page last revised:
August 27, 2000.