I love grep command on Linux, it helped to search and filter strings easily, always wonder what is the equivalent tool on Windows, and found this findstr recently.

In this article, I will share some of my favorite “grep” examples on Linux, and how to “port” it to Windows with “findstr” command.

1. Filter a result

1.1 Classic example to filter a listing result.

$ ls -ls | grep mkyong

c:\> dir | findstr mkyong

1.2 Add ignore case, and filter the listing result with multiple strings.

#Linux - Need '-E' option and Uses "|" to separate multiple search strings.
$ ls -ls | grep -iE "mkyong|music"

#Windows - Use spaces to separate multiple search strings
c:\> dir | findstr -i "mkyong music"

2. Search a File

2.1 Search matched string in a file.

$ grep mkyong test.txt

c:\> findstr mkyong test.txt

2.2 Counting the number of matches.

$ grep -c mkyong test.txt

#Windows - Piped with find /c command.
c:\> findstr -N "mkyong" test.txt | find /c ":"

3. Search a list of files

3.1 Search matched string in a list of files.

$ grep mkyong -lr /path/folder

c:\> findstr /M mkyong c:\folder\*

* (grep) -l , (findstr) /M = print only name of files containing matches.

4. Help

4.1 The most powerful command ~

$ grep --help 
$ man grep 

c:\> findstr -?
Do you have other examples? Does share it below, thanks.


  1. 15 Practical Grep Command Examples In Linux / UNIX
  2. Wikipedia : Findstr
  3. Grep for Windows Using FINDSTR