Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

findstr ms-dos command won't search sub directories

I had to switch off my windows search indexing in Windows 7 as the old hard disk was constantly making noise with indexing switched on!

Now I want to use Windows command prompt to search for a specific text term within all files located within the current directory and sub directories

How do I use the Windiows command findstr to search subdirectories?

Currently, when I open a command prompt and change directory to C:\Users\Damien\Documents\Research\2012July and run the command findstr "thesis" *.tex /S, I get the following error :

FINDSTR: Cannot open /s

This command will search the current directory if I remove /S, but I want to be able to search for text within subfolders also.

like image 874
DeadlyDan Avatar asked Feb 01 '12 14:02

DeadlyDan


1 Answers

You need to put /S at the beginning, i.e.:

findstr /S "thesis" *.tex

From the built in help:

C:\>findstr /?
Searches for strings in files.

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
        [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
        strings [[drive:][path]filename[ ...]]

Your modifiers/switches, whatever they are called, need to come before your pattern/string

like image 110
jon Avatar answered Oct 02 '22 18:10

jon