≡ Menu

Windows find command : syntax and examples

Using ‘Find’ command,  we can search for specific text in a set of files. Find below the syntax of this command with examples. Note that windows find command is different from the Linux find command in functionality. Linux find command is used to search for files that match the given criteria. But the windows find command is useful to search files for the lines that match the given string. The windows command that matches partially with Linux find command’s functionality is dir command.

Find the lines of a file that have the specified string

find "string" filename

Example:

C:\>find "Windows" C:\boot.ini
---------- C:\BOOT.INI
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

C:\>

To print line numbers along with the lines

find /N "string" filename

Ex:

C:\>find /N "Windows" C:\boot.ini
---------- C:\BOOT.INI
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

C:\>

To ignore case in searching for the string, we can add /I switch.

find /I /N "string" filename

In the below example, we don’t find any matching lines when we search for ‘windows’. In the next command, I have added /I and it shows the matching line ignoring the case differences.

C:\>find /N "windows" C:\boot.ini

---------- C:\BOOT.INI

C:\>find /N /I "windows" C:\boot.ini

---------- C:\BOOT.INI
[3]default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

C:\>

To find the lines that are not matching with the given string:

We can use /V switch for this case. Please find the command syntax below.

find /V  "string" filename

Ex:

C:\>find /N "windows" C:\boot.ini
---------- C:\BOOT.INI

C:\>find /N /I "windows" C:\boot.ini

---------- C:\BOOT.INI
[3]default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

C:\>
1 comment… add one
  • Dominik Lenné

    When I apply this
    find * “searchstring”
    all subdirectories are searched.

    I’d like to know, how I could limit the search to the current directory?

    Thx

Leave a Comment