Searching a string in a file anywhere on PC using Findstr

0

I have a text (.txt) file located somewhere on my PC that contains a bunch of data, including the following string:

Secret Username: ********* 
Secret Password: *********

How can I find this file from command-line, using Findstr?
I don't know if it's on C: drive or D: drive.

I tried various Findstr queries, such as:

findstr /s /m /n /i Secret Username C:
findstr /s /m /n /i Secret Username D:
findstr /s /m /n /i /c:"Secret Username"
findstr /s /m /n /r /i .*Secret Username.*

but couldn't find the file.

amiregelz

Posted 2012-11-18T16:06:28.300

Reputation: 6 965

Answers

3

findstr /S /M /I /C:"Secret Username" C:\*.txt

bummi

Posted 2012-11-18T16:06:28.300

Reputation: 1 569

It finds hundreds of files (lots of Java files), but there's no way they contain this string. Is it because it doesn't look for the whole string? – amiregelz – 2012-11-18T16:32:02.890

so sorry, there was a mistake, I did an Edit ... – bummi – 2012-11-18T16:54:10.927

Do you know if it starts searching from where cmd.exe is located or from the path showed in command-line itself (for me it's C:\Users\amiregelz)? – amiregelz – 2012-11-18T17:05:50.623

that's why it ends with C:*.*, you have credentials? – bummi – 2012-11-18T17:08:59.647

It doesn't find the file (I waited for more than 5 minutes) :-( Do you have any idea why? Also, please add /M to the query since otherwise it shows all the content of each file and it's not a good idea because the file I'm looking for contains a lot of data. – amiregelz – 2012-11-18T17:10:31.813

1The /N switch already limits the output to the matching line. Furthermore, the command handles about 1 GB a minute. There's a very rough estimate, but scanning the entire C:-drive typically takes a few hours as opposed to five minutes. You can limit the search to .txt-files for a significant performance boost. I have edited the answer accordingly. – Marcks Thomas – 2012-11-18T18:05:41.780

@MarcksThomas Thanks for the info, after searching for .txt only it found the file after 30 seconds. – amiregelz – 2012-11-18T18:13:00.747

@ Marcks Thomas thank you, sorry it didn't see (*.txt) .... – bummi – 2012-11-18T18:27:05.373

@MarcksThomas: /N prints the line number before each line that matches, whereas /M prints only the filename if a file contains a match. Since the file has to be located, /M should result in less lines of output and thus a faster search. – Karan – 2012-11-19T01:47:47.480