Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMD Search a directory to Find a string inside a file

I need to find the files in a directory that have specific strings, using Windows CMD prompt.

E.g., I need to find the files that have a string like this:

<h1>Select an Item</h1>
like image 293
ryanjohnsond Avatar asked Nov 20 '25 04:11

ryanjohnsond


2 Answers

"findstr" iswhat you are looking for.

findstr /I "<h1>Select\ an\ Item</h1>" *.*

findstr is the command, /I is a flag to match the string case insensitive. "<h1>Select\ an\ Item</h1>" is your string (note the escaped spaces!) and *.* means "in all files in this directory".

The basic syntax is findstr "seachString" filename.ext. You may replace filename.ext with *.ext or *.* to filter cretin file types or look in all files. This will look only in the current directory and not recursively.

More information about the command findstr documentation

like image 78
0xGiddi Avatar answered Nov 22 '25 03:11

0xGiddi


  1. Open up a Windows console (or CMD).
  2. Go to the folder, from where you want to start the search.
  3. Let's say you search for a text (e. g. "abc") in a folder, specifically in all the Word files (e. g. ".doc" and "docx"). Then the command should look like this
findstr /s /i /m /c:"abc" *.docx *.doc

Where /s searches recursively (including subdirectories), /i means it searches case-insensitive and /m prints only the file name if there is a match (more information on arguments can be found here).

You will get a list with all the Word documents that contain the text.

like image 29
Birol Efe Avatar answered Nov 22 '25 05:11

Birol Efe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!