Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a command prompt (Windows 7) grep equivalent? That is, I want to filter out the results of a command:

Bash use:

ls | grep root

What would it be from a Windows command prompt?

share|improve this question
don't confuse ms-dos with the command prompt. + use of find and findstr and even grep, for windows.. is surely easily found with a quick search. there are even tables of equivalent commands in linux and windows. also you bash example is not even specific to bash.. just I suppose, *nix OS. –  barlop Jun 22 '11 at 21:32

11 Answers 11

up vote 97 down vote accepted

Findstr sounds like what you want. I use it all the time as an approximate grep-equivalent on the windows platform.

Another example with pipes:

C:\> dir /B | findstr /R /C:"[mp]"
share|improve this answer
Yeah that seems to be what i'm looking for. I understand there are probably limitations. I'll give it a try. –  chrisjlee Jun 22 '11 at 21:11

There are several possibilities:

  • Use a port of a Unix grep command. There are several choices. Oft-mentioned are GNUWin32, cygwin, and unxutils. Less well known, but in some ways better, are the tools in the SFUA utility toolkit, which run in the Subsystem for UNIX-based Applications that comes right there in the box with Windows 7 Ultimate edition and Windows Server 2008 R2. (For Windows XP, one can download and install Services for UNIX version 3.5.) This toolkit has a large number of command-line TUI tools, from mv and du, through the Korn and C shells, to perl and awk. It comes in both x86-64 and IA64 flavours as well as x86-32. The programs run in Windows' native proper POSIX environment, rather than with emulator DLLs (such as cygwin1.dll) layering things over Win32. And yes, the toolkit has grep, as well as some 300 others.
  • Use one of the many native Win32 grep commands that people have written and published. Tim Charron has a native Win32 version of a modified GNU grep, for example. There are also PowerGREP, Windows Grep, Bare Grep, grepWin, AstroGrep, and dnGrep, although these are all GUI programs not TUI programs.
  • Use the supplied find and findstr. The syntax is different to that of grep, note, as is the regular expression capability.
share|improve this answer
cygwin worked for me nicely on Win 7. I needed grep and GnuWin32 grep did not work for me. –  Kozuch Feb 21 '14 at 11:58

If you would rather use grep, rather than findstr, there is a single .exe file version in UnxUtils, so it's portable and there is no need to install it, or use something like Cygwin.

share|improve this answer
This is interesting but would require installing that tool. –  chrisjlee Jun 22 '11 at 21:11
@Chris: There is no installation. It's just a .zip file of .exe files. The only small downside is that the versions are slightly old. –  paradroid Jun 22 '11 at 21:13
What's the downside of being old? Can software be old? All fresh bytes. –  user unknown Jun 23 '11 at 1:43
GnuWin32 also provides grep for Windows: gnuwin32.sourceforge.net/packages/grep.htm –  LiuYan 刘研 Jun 23 '11 at 1:54
@userunknown well, as an example, the unxutils sed command is older and doesn't support \d e.g. \d22 to specify quote. An older wget might not download a page that a newer one will, and if you ask for support they may ask that you get the latest one as that can solve some issues. A really old grep no doubt won't have the level of regex support that a current one has –  barlop Sep 3 '14 at 18:59

If PowerShell commands are allowed, use

PS C:\> Get-ChildItem | Select-String root

or short

PS C:\> ls | sls root

Be aware that the alias sls is only defined beginning with PowerShell version 3.0. You may add an alias for less typing:

PS C:\> New-Alias sls Select-String

To run the PowerShell command directly from cmd, use

C:\>powershell -command "ls | select-string root"
share|improve this answer

If you mean MS-DOS then there's only FIND, as far as I know. But it's an ancient OS not used anymore.

If you mean NT(XP/2K/7/Vista)'s Command Prompt you can use find, findstr and grep if you download GnuWin32.

The basic differences are that findstr has some regex support. Grep supports regex best.

C:\>dir | find "abc"  
C:\>dir | find /i "abc"

find /? and findstr /?shows you what the switches do.

If you download GnuWin32 I suggest the coreutils package for a bunch of basic useful utilities you'd be familiar with, but grep is a separate thing, its own package.

share|improve this answer

It may be useful.

$ cat demo_file
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.

Two lines above this line is empty. And this is the last line. 1. Search for the given string in a single file

The basic usage of grep command is to search for a specific string in the specified file as shown below.

grep "literal_string" filename

$ grep "this" demo_file

this line is the 1st lower case line in this file. Two lines above this line is empty. 2. Checking for the given string in multiple files.

grep "string" FILE_PATTERN

This is also a basic usage of grep command. For this example, let us copy the demo_file to demo_file1. The grep output will also include the file name in front of the line that matched the specific pattern as shown below. When the Linux shell sees the meta character, it does the expansion and gives all the files as input to grep.

    $ cp demo_file demo_file1
    $ grep "this" demo_*

demo_file:this line is the 1st lower case line in this file. demo_file:Two lines above this line is empty. demo_file:And this is the last line. demo_file1:this line is the 1st lower case line in this file. demo_file1:Two lines above this line is empty. demo_file1:And this is the last line. 3. Case insensitive search using grep -i

grep -i "string" FILE
share|improve this answer


Multi replacer program has been prepared so that many functions can be carried out by using command line parameters. Command line usage is seen below:

MultiReplacer [Multi Replacer File] | [Search files] | [Search folders]
[-Subs] [-NoSubs] [-IncPtr=pattern] [-ExcPtr=patterns] [-DestDir=destination]
[-DMWithinanhour] [-DMToday] [-DMYesterday] [-DMThisweek] [-DMThismonth]
[-CDMAfter=date] [-CDMBefore=date] [-MinFileSize=bytes count]
[-MaxFileSize=bytes count]
[-Search=text] [-Case] [-NoCase] [-Regex] [-NoRegex] [-SubMatchText=text]
[-StartSearch] [-StartReplace] [-AutoClose] [-StopAfterMatchThisFile] [-StopAfterMatchAll]
[-ExtractedWordsFile=filename] [-ExtractedLinesFile=filename] [-
share|improve this answer

You can still use your familiar grep and other Linux commands by downloading this tool UnxUtils and add it location to your PATH environment variable

share|improve this answer

You can try installing chocolatey on windows, and through that, install Gow tool.
This will provide you with grep on windows

Gow stand for GNU on windows. It provides unix command line utilities on windows.

share|improve this answer

You can use the dir command (DOS equivalent of ls) and find command (DOS equivalent of grep). For example, the following command lists the contents of the current directory and then pipes it into a find command which looks for the file "foo.c":

dir | find "foo.c"

share|improve this answer
This information was given in multiple answers over three years ago. Also stated: "DOS" is not relevant to a question about Windows 7 (even if it is a question about the command-line interpreter) –  G-Man Nov 15 '14 at 0:30

I wrote a Windows alternative to grep using Hybrid Batch\JScript code. I wrote this because getting the escape characters right in the GNU Win32 grep port was a real pain. This version works much more like how you would want the GNU version to work in Windows:

@set @junk=1 /*
@cscript //nologo //E:jscript %~f0 %*
@goto :eof */

var args=WScript.Arguments, argCnt=args.Length, stdin=WScript.StdIn, stdout=WScript.StdOut;
var replaceSingleQuotes=false, printMatchesOnly=false, matchString, flagString, regex, argDx=0;

if(argCnt==0) {
    throw new Error("You must provide search criteria.");

if(argCnt>1) {
    for(var bLoop=true; bLoop&&argDx<argCnt-1; argDx++) {
        switch(args(argDx)) {
        case '-t': replaceSingleQuotes=true; break;
        case '-o': printMatchesOnly=true; break;
        case '-g': flagString+="g"; break;
        case '-i': flagString+="i"; break;
        case '-m': flagString+="m"; break;
        default: bLoop=false; break;
if(replaceSingleQuotes) {
    matchString=args(argCnt-1).replace("'", '"');
} else {

if(printMatchesOnly) {
    while(!stdin.AtEndOfStream) {
        var sLine=stdin.ReadLine();
        if(flagString.Length) regex=new RegExp(matchString, flagString);
        else regex=new RegExp(matchString);
        var m,matches=[],startDx=0;
        while((m=regex.exec(sLine.substr(startDx))) !== null) {
} else {
    if(flagString.Length) regex=new RegExp(matchString, flagString);
    else regex=new RegExp(matchString);
    while(!stdin.AtEndOfStream) {
        var sLine=stdin.ReadLine();
        if(regex.test(sLine)) {


You can always find the latest version on my Gist page for this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.