text
stringlengths
0
4.23k
a
A
If the string you want to search for contains quotation marks, you must use double quotation marks for each quotation mark contained within the string (for example, """This string contains quotation marks""").
If you omit a file name, this command acts as a filter, taking input from the standard input source (usually the keyboard, a pipe (|), or a redirected file) and then displays any lines that contain string.
To exit the console search use CTRL-X or CTRL-z.
CTRL-X
CTRL-z
You can type parameters and command-line options for the find command in any order.
You can't use wildcards (* and ?) in the searched string. To search for a string with wild cards and regex patterns, you can use the FINDSTR command.
If you use /c and /v in the same command line, this command displays a count of the lines that don't contain the specified string. If you specify /c and /n in the same command line, find ignores /n.
This command doesn't recognize carriage returns. When you use this command to search for text in a file that includes carriage returns, you must limit the search string to text that can be found between carriage returns (that is, a string that is not likely to be interrupted by a carriage return). For example, this command doesn't report a match for the string tax file if a carriage return occurs between the words tax and file.
The command accepts wildcards for file names. When searching in file (or files) it will print the file of the processed file preceded by ten dashes.
Find command cannot read alternate data streams. For searching in alternate data streams use findstr, more or for /f commands.
Examples
To display all lines from pencil.md that contain the string pencil sharpener, type:
find "pencil sharpener" pencil.md
To find the text, "The scientists labeled their paper for discussion only. It is not a final report." (including the quotes) in the report.txt file, type:
find """The scientists labeled their paper for discussion only. It is not a final report.""" < report.txt
To search for a set of files, you can use wildcards. To search the current directory for files that have the extension .bat and that contain the string PROMPT ignoring the case, type:
find /i "PROMPT" *.bat
To find files names in a directory that contain the string CPU, use the pipe (|) to direct the output of the dir command to the find command as follows:
dir c:\temp /s /b | find "CPU"
Find all running processes that do NOT contain agent:
tasklist | find /v /i "agent"
Check if a service is running:
sc query Winmgmt | find "RUNNING" >nul 2>&1 && (echo service is started) || (echo service is stopped)
findstr
Searches for patterns of text in files.
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>[ ...]
Parameters
Parameter
Description
/b
Matches the text pattern if it is at the beginning of a line.
/e
Matches the text pattern if it is at the end of a line.
/l
Processes search strings literally.
/r
Processes search strings as regular expressions. This is the default setting.
/s
Searches the current directory and all subdirectories.
/i
Ignores the case of the characters when searching for the string.
/x
Prints lines that match exactly.
/v
Prints only lines that don't contain a match.
/n
Prints the line number of each line that matches.
/m
Prints only the file name if a file contains a match.
/o
Prints character offset before each matching line.
/p
Skips files with non-printable characters.
/off[line]
Does not skip files that have the offline attribute set.
/f:<file>
Gets a file list from the specified file.
/c:<string>