Using Find to Search in a Command Prompt Output

The Windows Command Prompt is a Command-Line Interface that allows you to access and configure Windows settings and details by using just the keyboard. As such, it has a ton of text-based utilities built right into it.

In the past, we have covered several of basic Command Prompt commands that every user should know along with guides on using network utilities like netstat to check open port in Windows and more.

In this guide, we will cover an essential Command Prompt utility called find which allows you to search through the outputs generated by any Command Prompt command you use to quickly access only the information you are looking for.

For example, if you want to use the netstat command to find the open ports on your PC but in this case, you only want to search for the ports that are in a listening state, you can use the find command in conjunction with the netstat command to accomplish this to go through the output generated by netstat and only access the ports in Listening mode.

Using Find to Search through an Output

  1. Type a command that you want to execute. For example, if you want to find all the ports in Listening state (read our guide over here),
    netstat -an
  2. Now if you execute this program – it will generate the complete output of all the open ports. For using find, add a pipe character after the command and then type find followed by find parameters,
    netstat -an | find /i “listening”

We use the /i program to allow find to search for the string given in the quotes without being case-sensitive. If we don’t use the /i, it will search for the exact string given to find and will be case-sensitive as well.

Here’s another example where we will be running ipconfig command to get the network configuration detail of our PC while using find to only get the local network IP of the PC.

ipconfig | find /i “192”

There are several other parameters we can use with the find command to configure the command according to our specific need. Here, we have listed them down,

/v Displays all lines that don’t contain the specified <string>.
/c Counts the lines that contain the specified <string> and displays the total.
/n Precedes each line with the file’s line number.
/i Specifies that the search is not case-sensitive.
[/off[line]] Doesn’t skip files that have the offline attribute set.
<string> Required. Specifies the group of characters (enclosed in quotation marks) that you want to search for.
[<drive>:][<path>]<filename> Specifies the location and name of the file in which to search for the specified string.
/? Displays help at the command prompt.

You can also use the find command to search through a file. We will be covering that in another guide.