Search From the Command Line – FIND Command (Windows, CMD, DOS)

What We'll Learn:

Welcome!
This guide is all about locating files folders or strings using the Find command in the Windows Command Line (Cmd).

  • We’ll start by learning, exactly what the Find command is and what function it servers.
  • How to use the Find command to locate files based on their contents.
  • How to use the Find command to locate exactly where a string is located within a set of files.
  • And finally, we’ll take a look at a few useful parameters as well as numerus usage examples

Lets get started!

What is the find command?​

While windows has some search capabilities from the GUI, searches are usually quite slow and they can not search within the contents of any files.

Often however it might be necessary for you to locate a file based on the text within it, such as for example when you don’t remember the name or location of a specific file but remember what was written within it.
That’s where the command find comes in.

You can use the find command to search for a file based on the contents inside it.

Alternatively, in a similar fashion, you can use the find command to find where a string is located within multiple files.

The find command is especially useful for programmers, writers or people that use lots of files in a frequent basis.

An alternative to the find command is findstr. The difference being that findstr has more search options and includes support for regular expressions, which makes it similar to the grep command in linux.

If you would like to follow along, open your command line and navigate to a directory of your choice (i.e. Desktop) and use the echo command along with a redirector to create two files.

echo Awesome > File1.txt & echo awesome > File2.txt

Two files should immediately be created in you current directory.

Now that our files have been created lets learn how to locate them using the FIND command.

How to use the find command to locate files:

To use the find command to check whether a file contains a specified string simply type “find” followed by the text you want to search for within quotes and the location or name of your text file.

Find "Awesome" "File1.txt"
FIND Command - Examples, Parameters & More (Windows, CMD, DOS)

Your file should be located at once.

If the string was found within your file the command line will output the name of the file and the string below it.

If the find command did not manage to find your text even tho you are sure that it is contained within your file, try using the /i parameter, which will ignore whether or not the case of the characters in the file is different from the ones in the provided string.

Find /I "Awesome" "File2.txt"
FIND Command - Examples, Parameters & More (Windows, CMD, DOS)

Your file or string should be located at once.

But what if we want to search within multiple files at once?

To search for a string inside multiple documents either enter the names or the locations of your text documents one after the other.

Find /I "Awesome" "File1.txt" "File2.txt"

Or alternatively take advantage of wildcards to search through every text document in a directory.

Find /I "Awesome" *.txt

Using wildcards you can even restrict your search to files that contain a specific word within their name.

Find /I "Awesome" *File*.txt

In this example the find command will only search through text files that have the word “file” in their name.

FIND Command - Examples, Parameters & More (Windows, CMD, DOS)

How to use the find command to locate strings:

So far we have been using the find command to locate files based on their contents, but what if we want to search for where a specific word or phrase is located within a single or multiple files?

To do so we would have to use the /n parameter which shows us the number of the line in which our string was found at.

Find /N /I "Awesome" *.txt

The number of the line in which the specified word or phrase was located at will immediately appear in our output.

Since both the name of the file that the string was found at as well as the location of said string is displayed with the use of the /n parameter, you can use the find command to search for both files that contain a string as well as strings within files.

Useful Parameters:​

  • /V Which displays every other string except the specified one.
  • /C which only displays the count of lines that contain the specified string.
  • /N Which displays the numbers of the displayed lines.
  • /I Which ignores any mismatch between the casing of the characters in the provided string and any string located within the file.

Find command examples:​

Searches for the word “Awesome” within the “Document.txt” file while ignoring any casing differences.

Find /I "Awesome" "Document.txt"

Searches every text document in the current directory for the word “Awesome”.

Find "Awesome" *.txt

Searches for the word “Awesome” within every text file in the desktop directory (replace with your computers name).

Find "Awesome" "C:\Users\\Desktop\*.txt"

Displays the number of the line in which the word “Awesome” was found at within the “Document.txt” file while ignoring any casing differences.

Find /I /N "Awesome" "Document.txt"

Displays the every line that does not contain the specified string within the “Document.txt” file.

Find /V "Awesome" "Document.txt"

Displays how many times the string was found in the specified file.

Find /C "Awesome" "Document.txt"

 

Help Output:

Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

Summary:

  • The Find command searches for a file based on the contents inside it, or locates a string within multiple files.
  • Locate files based on their contents by using the Find command followed by a string and the names of your files.
  • Locate a string within a set of files by once again using the Find command along with the /N and /I parameters, your string and the names of your files.

That's It!

You now know how to use the Find command to locate files and strings from the Windows Command Line.

If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.

Dont Stop Learning!

Windows Command Line Course!

This course has everything you need to start learning about the windows command line along with batch scripting.

Read More:

Any Questions? Ask them Below:

Leave a Reply

Your email address will not be published.

Take Your Skills to the next level!
Become one of our beloved students by enrolling into one of our courses. Get started now!

Command Line Course!

Learn the Windows command line And Become an Expert!

Learn The Windows Command Line!

No more searching or memorizing commands!

Welcome

You are now officially on your way to becoming a genius!