CMD Where Command | Find Files Using Command Prompt

windows where command

In the Windows command prompt (CMD), we use the where command to find files that match a specific search pattern.

where /r dir file_name

The where command searches for files in the given directory and all subdirectories and returns the full path of each matching file to the standard output.

First, let's look at a few examples to understand how CMD where command works.

Examples

Search c:\ drive for the file file1.txt:

where /r c:\ file1.txt

Find the location of the chrome.exe:

where /r c:\ chrome.exe

The following command finds all files that contain "report" anywhere in the filename in the c:\windows and all subdirectories:

where /r c:\windows *report*

This command search c:\ drive to find filenames starting in "report":

where /r c:\ report*

The following command search c:\ drive to find filenames ending in "report":

where /r c:\ *report

In this example, every file in the c:\windows (and all subdirectories) is searched for filenames ending in .txt:

where /r c:\windows *.txt

Find all mp3 files in the d:\ drive:

where /r d:\ *mp3

The following command finds all mp3 files in the d:\ drive and copies the output to the clipboard instead of printing it to the command prompt.

where /r d:\ *mp3 | clip

In this example, we save the output to a text file called output.txt:

where /r d:\ *mp3 > C:\output.txt

Add the /t option to display the file size and last modification date and time:

where /t /r c:\windows *.log

Command Options

/r DirSpecify the directory to search (the search is recursive).
/fIf you use this option, the where command encloses filenames in quotation marks in the output.
/tDisplays file size and last modification date.
/?Displays command options.

If you know the exact name of the file you want to find, then specify the name without using any wildcards:

where /r c:\ file1.txt

The above command will search for file1.txt in C: drive recursively.

cmd where command

If you don't know the exact name, but only a part of it, then put an asterisk (*) before and after the search term, as shown in the following example:

where /r c:\Docs *report*

In the above example, CMD where command will return any files that have the string report anywhere in the filename.

Find files using the where command

To find files that start with a specific pattern, put an asterisk (*) after the search term, as shown in the following example:

where /r c:\ report*

To find files that end with a specific pattern, put an asterisk before the search term:

where /r c:\ *report

In the following example, the where command finds all files that have the .avi extension on the C: drive:

where /r c:\ *.avi

Remarks

  • You can only use the where command to find files on CMD. It will not work on Windows PowerShell.
  • Run the where /? command to see a list of all the options.