How to tell if command prompt is working?

0

Another life ago I used to build PCs, but have been a Mac girl for so long now... this question is almost embarrassing but it's driving me nuts.

I'm using command prompt findstr to search website contents for a particular call: findstr /I /S /P "search string".

My question, though, is how to tell if it's working? Whenever I execute this command it never seems to go anywhere or pull any results, 0 or otherwise. It won't let me do anything else (like dir or CD) so I assume it's working, but no matter how long I wait nothing happens.

Is there any way to tell where in the search it is or how long it might take?

kristina childs

Posted 2013-03-26T16:56:47.803

Reputation: 103

/S searches for matching files in the current directory and all subdirectories. If you have a lot of files in those directories, that's going to take a long time. A very long time. Also, that won't search the contents of a website, unless you downloaded the website contents beforehand and placed them within the current directory (or a subdirectory). – Bob – 2013-03-26T17:01:46.263

3The way to test this kind of thing is to create a small text file that contains you string and see if it works there. If it hangs with a 3-line text file, you know something is wrong with the command. – terdon – 2013-03-26T17:01:47.620

@terdon the /S option, in effect, specified the files to search. Which can be a heck of a lot. Even if searching only within the user profile, that can easily be gigabytes of data with tens of thousands of files. Don't even think about doing that in the drive root in any reasonable amount of time. – Bob – 2013-03-26T17:03:01.393

This is the wwwroot directory of a web server and we are currently doing penetration testing. We found some security holes so I am trying to find all html documents that call this particular file to find all pages that need to be fixed. So yeah, the directory will have a lot of files to scan. – kristina childs – 2013-03-26T17:04:00.487

@kristinachilds How long have you waited? This should just print results as it finds them. Blank is supposed to mean it's searching. (Personally, I like Notepad++'s find when searching for text in files in a directory.) – Bob – 2013-03-26T17:16:30.840

The last search started about an hour ago. Still nothing. Notepad is able to search file contents within entire directories?? – kristina childs – 2013-03-26T17:34:53.983

Install Cygwin and use grep. – Daniel R Hicks – 2013-11-03T19:25:30.130

Answers

2

If I understand the findstr documentation correctly, you can also specify which files to search in. That should speed things up (searching only *.html) and so should telling findstr to only report matches (/m) rather than printing each matching line. I guess the /m flag will cause findstr to exit as soon as the first match is found so it won't need to process the entire file. Something like this:

findstr /I /s /p /m "search string" *.htm*

I used /s and /p because I could not see /S or /P in the documentation and guessed that is what you meant.

To check it is working, either run it on a small file as I suggested in the comments, or create an html file that contains your string in the same directory you are launching the command from. That way, it should report that it found that one very quickly and you will know it is working.

terdon

Posted 2013-03-26T16:56:47.803

Reputation: 45 216

Thanks, I will try this. I looked over the documentation but didn't see if there was a way to do multiple filetypes. Do you know offhand if there's a way to do that? Like *.htm* *.asp *.php *.inc etc? – kristina childs – 2013-03-26T17:41:08.083

Nope, no idea sorry. I've never really used the windows command line. Can't you get access to these directories on a Mac or Linux system so you can use some standard UNIX tools? I can see various ways of making this easy on *nix but my windows-fu is pitifu(l). – terdon – 2013-03-26T17:45:02.443

unfortunately this is on a windows server, so i'm limited to the windows os tools. not my decision, but it is what it is. – kristina childs – 2013-03-26T17:52:31.760

I know, I was just thinking of whether you could access it over Smb or something. I feel your pain, I hate being forced to work without my preferred OS. – terdon – 2013-03-26T17:56:20.760

Yeah. I'm no OS fundamentalist... they each do some things better than others. But when it comes to website administration, Unix tools are far superior. I hate working on windows servers. Bleh. – kristina childs – 2013-03-26T18:39:35.497

I took your advice and created a single-file directory with the search string. Using the findstr command as I was, it wasn't executing properly. You have to include some sort of filetype call, so to search all filetypes the command is *.*. So the working command in full looks like findstr /s /i /m searchstring *.* (it also helped to remove the quotation marks as this was throwing it off). Thanks for the help! – kristina childs – 2013-03-26T19:02:48.797