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.
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.
- 01.02.2020
- 17 009
- 0
- 04.08.2021
- 12
- 12
- 0
- Содержание статьи
- Описание
- Синтаксис
- Параметры
- Примечания
- Примеры
- Справочная информация
- Добавить комментарий
FIND — Поиск заданной строки текста в файле или нескольких файлах.
Описание
После поиска в заданных файлах команда find выведет на экран все строки из этих файлов, содержащие заданный образец.
Синтаксис
find [/v] [/c] [/n] [/i] "строка" [[диск:][путь]ИмяФайла[...]]
Параметры
Параметр | Описание |
---|---|
/v | Выводит все строки, не содержащие строку, заданную параметром строка |
/c | Подсчет строк, содержащих строку, указанную параметром строка, и отображение общего количества |
/n | Выводит номера строк перед самими строками |
/i | Задает поиск без различия строчных и заглавных букв |
«строка_поиска» | Обязательный параметр. Указывает группу символов, поиск которой будет производиться. Необходимо заключить параметр строка в кавычки («строка») |
[диск:][путь] ИмяФайла | Задает местоположение и имя файла, в котором будет производиться поиск заданной строки символов |
/? | Отображение справки в командной строке |
Примечания
- Если ключ /i не указан, команда find ищет именно то, что указано в параметре строка. Например, для команды find символы «a» и «A» являются различными. Если используется ключ /i, команда find не различает строчные и прописные буквы, и символы «a» и «A» являются одинаковыми.
- Если строка поиска содержит кавычки, при вызове команды каждая кавычка в строке поиска должна быть заменена двумя символами кавычек («СтрокаСодержания»»Кавычки»).
- Если имя файла пропущено, find действует как фильтр, получая ввод из стандартного источника вывода (обычно клавиатура, канал или файл перенаправления), и выводит все строки, содержащие параметр строка.
- Параметры и ключи команды find могут быть заданы в произвольном порядке.
- Подстановочные знаки (* и ?) не могут быть использованы в именах файлов и расширениях, задаваемых в команде find. Чтобы искать строку в множестве файлов, указанных с помощью подстановочных знаков, можно использовать команду find в команде for.
- Если в одной команде заданы ключи /c и /v, команда find выведет на экран количество строк, которые не содержат заданную строку поиска. Если в одной команде указаны оба ключа: /c и /n, команда find игнорирует ключ /n.
- Команда find не распознает символ перевода строки. Когда команда find используется для поиска текста в файле, который содержит символы перевода строки, необходимо ограничить строку поиска текстом, который может быть найден между символами перевода строки (строка не может прерываться символом перевода строки). Например, find не найдет совпадение для строки «файл налогов» если перевод строки в файле стоит между словами «файл» и «налогов».
Примеры
Для вывода всех строк из файла Pencil.ad, которые содержат слова «Точилка» служит следующая команда:
find "Точилка" pencil.ad
Для поиска строки, содержащей текст, указанный в кавычках, необходимо сначала заключить в кавычки всю строку. Во-вторых, необходимо использовать двойные кавычки для каждых кавычек, содержащихся в строке. Для поиска фразы «Точилка» (именно с ковычками в файле Pencil.ad:
find ""Точилка"" pencil.ad
Если поиск требуется провести в нескольких файлах, следует использовать команду find с командой for. Для поиска файлов с расширением .bat, содержащих строку «PROMPT», можно использовать следующую команду:
for %f in (*.bat) do find "PROMPT" %f
Для поиска на жестком диске C файлов, содержащих строку «CPU» и отображения их имен используйте символ канала (|), чтобы направить результаты команды dir в команду find:
dir c:\ /s /b | find "CPU"
Так как команда find проводит поиск, различая строчные и заглавные буквы, а команда dir выводит результаты заглавными буквами, необходимо задать строку «CPU» заглавными буквами или использовать ключ /i в команде find.
Справочная информация
on April 19, 2011
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:\>
- SS64
- CMD
- How-to
WHERE.exe
Locate and display files in a directory tree.
The WHERE command is roughly equivalent to the UNIX ‘which’ command. By default, the search is done in the current directory and in the PATH.
Syntax WHERE [/R Dir] [/Q] [/F] [/T] Pattern ... WHERE [/Q] [/F] [/T] [Path;Path;... :]Pattern ... In PowerShell: C:\Windows\System32\WHERE.exe ..options as above key /R A recursive search, starting with the specified Dir directory. /Q Don’t display the files but return either an exit code of 0 for success or 1 for failure. /F Display the output file name in quotation marks. /T Display the size, time stamp, and date stamp of the file. pattern The Drive\Directory\file, or set of files to be found. you can use wildcard characters ( ? * ) and UNC paths. The pattern can also be $ENV:Pattern where ENV is an existing environment variable containing one or more paths. Path One or more semicolon-separated paths to search.
The WHERE command can either perform a recursive search within one directory (/R) or search through a list of folders (Path;Path:), but not both.
By default, WHERE searches the current directory and the paths specified in the PATH environment variable.
Unlike the DIR command WHERE always returns the full path to each file found.
The WHERE command is particularly useful to reveal multiple versions of the same comand/script/utility on the system PATH.
WHERE will use the PATHEXT variable to include all executable files, so WHERE robocopy will find the location of robocopy.exe
This PATHEXT expansion applies even if you are not searching for an executable. For instance, the command WHERE monday.csv will list the file monday.csv in the current directory, as expected, but this will also list files like monday.csv.exe, monday.csv.com should they exist.
To avoid this behaviour, clear the PATHEXT variable temporarily with Set «PATHEXT=»
To run the WHERE command from PowerShell it is necessary to specify the .exe extension: ‘WHERE.exe‘ otherwise the Where-Object cmdlet will take precedence.
Examples
Find all files named ‘Zappa’ on the remote computer ‘Server64’ searching
the subdirectories of Share1:
C:\> WHERE.exe /r \\Server64\Share1 Zappa.*
List all the files in the Demo folder:
C:\> WHERE «C:\demo\:*.*»
List all the .CSV files on both the work and play folders:
C:\> WHERE C:\work\;C:\Play\:*.csv
In PowerShell, find all copies of robocopy.exe in the current system path:
PS C:\> WHERE.exe robocopy.exe
“Who never walks, save where he sees men’s tracks, makes no discoveries” ~ Josiah Gilbert Holland
Related commands
Which.cmd — Show full path to executable.
OldNewthing — Describes the one-line ‘whereis’ batch file below:
@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT «%%~$PATH:i»==»» echo %%~$PATH:i
whereis utility (Archive.org) — Flounder.com, this uses an actual kernel call rather than simulating what the path might return.
Which — several scripts from Rob Vanderwoude.
ATTRIB — Display or change file attributes, when used to list items, ATTRIB will return similar results to WHERE.
CD — Change Directory.
DIR —
Display a list of files and subfolders.
TYPE — Display the contents of a text file.
Advanced Query Syntax (AQS) in Windows File Explorer.
Equivalent bash command (Linux): which — Show full path of commands.
Equivalent PowerShell cmdlet, finds the first copy only: (get-command robocopy.exe).Definition
Copyright © 1999-2025 SS64.com
Some rights reserved