Is it possible to make the Windows find command output ONLY when there are results found? Having such simple search command:

find "str1" *.* 

regardless of the "str1" string is found or not the find always outputs the file name scanned, like this:

---------- FILE1.TXT

---------- FILE2.TXT
This is a line in file2.txt that contains str1.

---------- FILE3.TXT

I'd like to see ONLY the files that contain the string "str1".

  • What's the latest on your question regarding the answer below which I provided? Have you been able to test and consider this solution? Commented Feb 14, 2021 at 22:09

2 Answers 2


Use findstr rather than find to get the file name and line content of matches only. Or use it to get the file name only of any file(s) that contain any number of matches.

This solution doesn't require complex batch logic or putting the find command in a loop to parse output and such to get the expected result(s).


findstr "str1" *.*


File.txt:"something","str1","something else"
File.txt:"str1","same file","different line"
File2.txt:"some line","str1","different file"
File9.txt:"another line","different file","str1

Output Explained

File.ext:display whole line containing matching string

Note: This shows the file name each time for each line in any file that a matching string is found—and it also displays the line content which the matching string is found.

Command 2

findstr /M "str1" *.*



Note: This shows the file name only and only once for each matching file containing any matching string within its content.

Supporting Resources

  • Findstr

    /I   Case-insensitive search.    
    /S   Search subfolders.
  • @Daros911 If you wanted to get a better result you have many more options with PowerShell but since you are asking about finding a string with batch and the find command in particular, I took a stab at giving you a solution using findstr which is designed and built in with Windows more tuned for the purpose of finding strings in particular than even the find command. Commented Jan 28, 2021 at 0:55

You can just use find . -name 'str1' to search recursievly in the current directory.

  • 2
    The question is about the Windows find command, which is the Windows equivalent of the grep command.  Your answer is for Unix/Linux. Commented Jan 28, 2021 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .