Search of a file using command prompt

command linesearch

In MS Windows XP, in DOS, is it possible to do a content search(for a line or a word) in a file using command prompt.?

If so can we search a directory as well.? i.e it should search all the files in the directory for a specific word or phrase.

Thanks.

Best Answer

There are two options: FIND or FINDSTR, both of which are built-in to the Windows Command Prompt.

You can use FIND to search for a simple string in a file:

FIND "apple" file.txt

You can also use it to search all files in the current directory:

FIND "apple" *

FINDSTR has a few more options: you can do searches with regular expressions, and you can search recursively into subdirectories:

FINDSTR /s "apple" *

In all cases, these commands print each line that matches the string to be searched, along with the file they were found in.

Related Question