Ron Sparks Author, Poet

Searching Contents of Files Via MS-DOS

S

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.

About the author

Ron Sparks

Ron Sparks is a technology professional, science fiction and fantasy author and poet living in Zurich, Switzerland. His latest book "ONI: Satellite Earth Series Book 1" is available on Amazon.com.

Add Comment

Ron Sparks Author, Poet

Select a Category to Browse

Ron Sparks

Ron Sparks is a technology professional, science fiction and fantasy author and poet living in Zurich, Switzerland. His latest book "ONI: Satellite Earth Series Book 1" is available on Amazon.com.

Welcome

A man of many passions, I lay claim to a myriad of interests and hobbies. Among them, I am an amateur astronomer, an avid motorcycle rider, a whiskey aficionado, a (poor) surfer, a scuba diver, a martial artist, a student of philosophy, a proponent of critical thinking, a technologist, an entrepreneur, a cancer survivor, and I harbor a lifelong love of science fiction and fantasy. Feel free to strike up a conversation on the social networks below.

Site Pages