Last Updated :
13 Mar, 2025
Ever lost a file on your computer and wished there was a quick way to find it without clicking through endless folders? Say hello to the Windows Command Prompt (CMD) a powerful little tool that can help you search for files fast. In this how-to blog, we will explore the steps to search for files using CMD simple commands, so you can find what you need in no time, no fancy software required.
So without further ado, let’s get into the process of finding files using CMD in Windows 10 and well in Windows 11.
How to Find Files Using CMD in Windows?
In this section we have mentioned some steps, so follow the few steps to get the lost file or file that you are looking for.
Step 1: Open CMD
To find your file first, open CMD or Windows Command Prompt, and to do this, click the Win+R button and type CMD, or you can click the Windows key and type CMD to open Windows Command Prompt.
Step 2: Use DIR Command
After successfully launching the Command Prompt, type the below command and press Enter to pull up a list of files and folders.
dir
Step 2: Use CD Folder Command
For moving down into a particular directory, use the below command followed by a folder name, until you reach the folder you want to search.
cd folder_name
Step 3: Use Aging DIR Command
Now type the dir command again but this time with your search term, follow dir with your search term in quotes with an asterisk term before closing the quotes (For example, type dir “Raveling*”) and press Enter. The command prompt will show you the file location along with the list of files name starting with a similar keyword.
The asterisk is what’s known as a wildcard and, in our example, it stands for anything that follows the word ‘highlands’, such as ‘raveling.doc’, ‘raveling.xls’ or My Business plans.txt’.
If you don’t know the exact location of your file in your hard drive, then instead of manually navigating through your directories, start searching from the very top level of your hard drive and include every sub-folder.
Step 4: Use Raveling Command
The top level of the drive is represented by a backslash and, to include subdirectories, you add a forward slash and ‘s’ to the end of the query as shown below:
dir “\Raveling*” /s
The above command is my all-time favorite because, with the help of this command, I don’t have to force my brain to remember the location of the files. This trick usually takes seconds to search the entire drive for the file.
You can also search for a particular file type by using a command dir \*.pdf /s and it will show you all files saved with the .pdf extension. You can try this for other files too (for example: .doxc, .png, .exe and more).
Note: The position asterisk symbol in the command matters a lot so type carefully and check once before executing the command.
How All The Commands Works?
Now you know enough to find any file on your entire hard drive within few seconds but if you are more curious to know how all these commands are working and what all these symbols stand for, then continue reading this post.
Let’s discuss each term one by one:
- dir command is for showing files on the current directory, but it can also show files from anywhere in the drive of the system.
- / tells dir to search from the top-level or root directory of the hard drive.
- /s is used for searching sub-directories.
- * asterisk is using before text (for example *.pdf) show all files ending with .pdf and * using at the end (for example raveling*) show you all file-names starting with that word.
Conclusion
Using the Command Prompt to search files in CMD is a valuable skill for anyone who frequently navigates through files and directories on a Windows system. By understanding the various commands available, you can easily find files with CMD and streamline your workflow. Whether you’re searching by name, location, or content, this method ensures that you can quickly locate the files you need with minimal effort.
If you are an advanced user of Windows, you might want to use the command line to find files on your system. You can use the command line to find files by date, content, size, and location, etc. In this article, I will show you how to use various methods and commands to find files using the command line in Windows 10/11.
Basic File Search Commands
One of the simplest ways to search for files using the command line is to use the dir and findstr commands. The dir command lists the files and folders in a directory, and you can use it with wildcards (*) to find file by name or extension from the Windows command line. For example, to use CMD to search for files with the extension TXT in the current directory, you can use the command:
dir *.txt
The Findstr command searches for a string of text in a file or files. You can use it with the /i option to ignore case sensitivity and with the /s option to search in all subdirectories. For example, to search for the word “hello” in all text files in the current directory and its subdirectories, you can use the command:
findstr /i /s "hello" *.txt
CMD Find File Name Containing a String
As mentioned, you can use the dir command to find a file name containing a specific string. For example, to find a file name containing the string “share” in the current directory and its subdirectories, you can type:
dir /s /b *share*
This will return a list of file names that match the pattern. The /s switch tells the command to search in all subdirectories, and the /b switch tells it to display only the bare file name.
You can also use wildcards to specify more complex patterns. For example, to find a file name that starts with “report” and with extension “.docx”, you can type:
dir /s /b report*.docx
Advanced File Search Commands
The find command searches for files that match certain criteria, such as name, size, date, and attributes. You can search words within files using the command prompt.
For example, to search for the word “hello” in all text files in the current directory, you can use the following command:
findstr /i /m "hello" *.txt
To search for all files larger than 1 MB in the C: drive, you can use the command:
forfiles /P C:\ /S /C "cmd /c if @fsize gtr 1048576 echo @path"
where Command for Executable Files
If you want to search for executable files, such as programs and applications, you can use the where command. It is mainly for locating executable files in a specified path or paths. You can use wildcards (*) with the where command to search for files with a specific name or extension. For example, to search for all executable files with the word “chrome” in their name in the C: drive, you can use the command:
where /r C:\ *chrome*.exe
Combine Dir and Find Commands
You can also use advanced filtering options with the dir command to search for files based on their attributes, such as size, date, and extension. You can use various switches with the dir command to filter your results. For example, to search for all readonly files in the current directory, you can use the command:
dir /a:r
To search for all files modified after January 1st, 2024 in the current directory, you can use the command:
dir /t:w /o:d | findstr /b "01/01/2024"
To search for all PDF files smaller than 100 KB in the current directory and its subdirectories, you can use the command:
dir /s *.pdf | findstr /v "<DIR>" | findstr /v "bytes" | findstr /r "[09][09][09] KB"
Windows CMD Find File Recursively
If you want to perform recursive searches using the dir command, you can use the /s switch. The /s switch searches for files in the current directory and all its subdirectories. For example, to search for all text files in the current directory and its subdirectories, you can use the command:
dir /s *.txt
Recursive searches are useful for locating files that are buried deep in your system’s folders.
You can also use the Where command to search recursively. For example, to list all files that start with “ffmp” in the c:\windows directory and its subdirectories, use the following command:
where /r c:\users ffmp*
PowerShell Commands for File Searches
PowerShell is a powerful command line tool that allows you to perform various tasks on your system. You can also use PowerShell commands to find files based on various criteria. For example, to search for all text files that contain the word “hello” in the current directory and its subdirectories, you can use the command:
Get-ChildItem -Path .\* -Include *.txt -Recurse | Select-String -Pattern "hello"
To search for all files larger than 1 MB in the C: drive, you can use the command:
Get-ChildItem -Recurse -Path C:\ | Where-Object {$_.Length gt 1MB}
To search for all PDF files created before January 1st 2024 in the current directory and its subdirectories, you can use the command:
Get-ChildItem -Path .\* -Include *.mp4 -Recurse | Where-Object { $_.CreationTime -lt '2024-01-01' }
Common CommandLine File Search Parameters
Here are some general tips for optimizing your command line file searches in Windows:
- Use wildcards (*) to search for files with a specific name or extension.
- Use the /s switch with the dir, find, and findstr commands to search in all subdirectories.
- Use the /r switch with the where command to search in a specified path or paths.
- Use the /a switch with the dir and find commands to filter files by attributes, such as hidden, readonly, system, etc.
- Use the /t switch with the dir command to filter files by date, such as creation, modification, or access.
- Use the /o switch with the dir command to sort files by name, size, date, or extension.
- Use PowerShell commands to perform more advanced file searches with various criteria.
Conclusion
In this article, I have shown you how to find files using the command line in Windows 11/10. Hopefully, you have learned to use advanced filtering and sorting options with these commands to get your results quickly.
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 Dir | Specify the directory to search (the search is recursive). |
/f | If you use this option, the where command encloses filenames in quotation marks in the output. |
/t | Displays 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.
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.
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.
Sign in to your How-To Geek account
Quick Links
-
Find’s Switches and Parameters
Find is another great command line tool that every Windows user should know about because it can be used to search content of files for specific strings of text.
Find’s Switches and Parameters
As with every command prompt based tool in Windows, there are certain switches and parameters you will need to know in order to use the tools effectively. These are listed and explained below.
- /v – This switch will show any lines that don’t contain the string of words you specified.
- /c – This switch tells the find tool to count how many lines contain your search terms.
- /n – This switch shows the numbers that correspond with the lines.
- /i – This switch tells find to ignore the case of text you are searching for.
In addition to these switches, there are two parameters which you can specify with this tool.
- «String» – The string will be the words you are searching for in your documents. You must always remember to keep this secrtion surrounded by quotation marks, otherwise your command will return an error.
- Pathname – This parameter is where you will specify the location that you want to search. This can be as broad as listing a drive or as specific as defining a single or multiple files. If you don’t specify a path, FIND will ask you for text input or may accept text piped from another command. When you are ready to end the manual text input, you can press “Ctrl + Z.” We will discuss this more later.
Find’s Syntax
Like every tool in windows, you will need to know how to enter your commands. The syntax below is the perfect model.
FIND [SWITCH] "String" [Pathname/s]
Depending on your command, you will receive one of three %errorlevel% responses.
- 0 – The string you were searching for was found.
- 1 – The string you were searching for was not found.
- 2 – This means you had a bad switch or your parameters were incorrect.
Let’s Practice
Before we get started, you should download our three sample text documents which we will use for the test.
- document
- sample
- exercise
These documents each contain a paragraph of text with a few similar word groupings. Once you have downloaded these three documents, you can copy them into any folder on your computer. For the purposes of this tutorial, we will put all three text documents on the desktop.
Now you will need to open up an elevated command prompt window. Open the start menu in Windows 7 and 10 or open the search function in Windows 8 and search for CMD. Next, right-click on it and then press “Run as administrator.” While you don’t need to open an elevated command prompt window, it will help you to avoid any pesky confirmation dialog boxes.
Our tutorial today will cover several simple scenarios which will be elaborated on below.
- Search a single document for a string of words.
- Search multiple documents for the same string of words.
- Count the number of lines in a file or multiple files.
Scenario 1 – Search a single document for a string of words.
Now that you have your three documents downloaded, we will enter a command to search the text file called “exercise” for the words “martin hendrikx.” Use the command shown below. Remember to put your search string in quotation marks and change the path to match the folder where your documents are saved.
find "martin hendrikx" C:\Users\Martin\Desktop\exercise.txt
You will notice that no results showed up. Don’t worry, you did nothing wrong. The reason you have no results is because FIND is looking for an exact match to your search string. Let’s try it again, but this time, let’s add the “/i” switch so that FIND ignores the case of your search string.
find /i "martin hendrikx" C:\Users\Martin\Desktop\exercise.txt
Now you can see that FIND brought up one line that matches the search string, which means it is working. Let’s try this again, but change the search string to “sushi”; if your results look like the image below, you did it right.
Scenario 2 – Search multiple documents for the same string of words.
Now that you know how to do a basic search, let’s try to widen the span of the search. We will now search two of the text files (exercise and sample) for the term “sushi.” Do this by entering the following string. Remember to change the path to match the location of your files and add the “/i” switch so that your search is not case-sensitive.
find /i "sushi" C:\Users\Martin\Desktop\exercise.txt C:\Users\Martin\Desktop\sample.txt
You will notice that the search terms were found in both documents and the sentences in which they were found, are listed under their corresponding file names and locations. Try this again, but this time, add the third file to the FIND command and search for the word “potato” instead. Your search results should look like the image below.
Note that the text found in each document is actually “potatoes” which means that even if you type a part of a word, you will see any phrases that contain the search string. Alternatively, you could use this command to check all text files.
find /i "sushi" C:\Users\Martin\Desktop\*.txt
Scenario 3 – Count the number of lines in a file.
If you want to know how many lines there are in a file, you can use the search command below. Remember to add a space between all your switches. In this case, we will replace the pathname with that of the “sample.txt” file. If you want only a number as your result, use this command:
type C:\Users\Martin\Desktop\sample.txt| find "" /v /c
If you want the number and the file info, use this command:
find /v /c “” C:\Users\Martin\Desktop\sample.txt
If you want to count the lines in multiple files on the desktop, use the following command.
find /v /c “” C:\Users\Martin\Desktop\*.txt
You can now experiment with a few different commands and familiarize yourself with the tool. It can help to save a lot of time in the future once you have a system created. Have fun and keep on geeking.
Image Credit: Littlehaulic on Flickr.com