Searching Contents of Files Via MS-DOS

I log into a lot of client production servers and do not have the luxury of installing my favorite GUI tools, such as UltraEdit, which (among other things) easily allows me to search within files.  On these servers I am limited to what is already installed.  Just today I was forced to search an entire website on a client server for a file that that might contain the string “bill”.

So I turned to my trusty DOS skills and utilized the little-known findstr command.  I typed in my command, piped the output to a text file, and viola! I had my results and quickly found the file I was looking for.

FINDSTR /S /N /I /C:”bill” * > find.txt

I was looking for a literal string (/C:) “bill” in all files (*)  in all sub directories (/S), without case-sensitivity (/I), outputting the line number the match was found in (/N) and outputting it all to a file instead of the console (> find.txt).

FINDSTR is really quite useful if you have no other tools available to you.

Syntax

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]
[strings] [[drive:][path]filename[ …]]
/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L Uses search strings literally.
/R Uses search strings as regular expressions.
/S Searches for matching files in the current directory and all subdirectories.
/I Specifies that the search is not to be case-sensitive.
/X Prints lines that match exactly.
/V Prints only lines that do not contain a match.
/N Prints the line number before each line that matches.
/M Prints only the filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/A:attr Specifies color attribute with two hex digits. See “color /?”
/F:file Reads file list from the specified file(/ stands for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of directories
strings Text to be searched for.
[drive:]
[path:]
filename
Specifies a file or files to search.
Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: