How to do a simple file search in cmd

WindowsCommand LineCmd

Windows Problem Overview


I want to quickly search for a file given its name or part of its name, from the windows command line (not power shell). This is similar to opening explorer and using the search box at the top.

Note: dir can search based on a string template but it will not search in the subdirectories.

Note2: findstr can be used to search for a token inside files and has a recursivity flag; it's funny that a more complex find can be easily discovered ...

Windows Solutions


Solution 1 - Windows

dir /s *foo* searches in current folder and sub folders.

It finds directories as well as files.

where /s means(documentation):

> /s Lists every occurrence of the specified file name within the > specified directory and all subdirectories.

Solution 2 - Windows

dir /b/s *.txt  

searches for all txt file in the directory tree. Before using it just change the directory to root using

cd/

you can also export the list to a text file using

dir /b/s *.exe >> filelist.txt

and search within using

type filelist.txt | find /n "filename"

EDIT 1: Although this dir command works since the old dos days but Win7 added something new called Where

where /r c:\Windows *.exe *.dll

will search for exe & dll in the drive c:\Windows as suggested by @SPottuit you can also copy the output to the clipboard with

where /r c:\Windows *.exe |clip

just wait for the prompt to return and don't copy anything until then.

EDIT 2: If you are searching recursively and the output is big you can always use more to enable paging, it will show -- More -- at the bottom and will scroll to the next page once you press SPACE or moves line by line on pressing ENTER

where /r c:\Windows *.exe |more

For more help try

where/?

Solution 3 - Windows

dir *.txt /s /p will give more detailed information.

Solution 4 - Windows

Problem with DIR is that it will return wrong answers. If you are looking for DOC in a folder by using DIR *.DOC it will also give you the DOCX. Searching for *.HTM will also give the HTML and so on...

Solution 5 - Windows

You can search in windows by DOS and explorer GUI.

DOS:

  1. DIR

  2. ICACLS (searches for files and folders to set ACL on them)

  3. cacls ..................................................

  4. example

icacls c:*ntoskrnl*.* /grant system:(f) /c /t ,then use PMON from sysinternals to monitor what folders are denied accesss. The result contains

access path contains your drive

process name is explorer.exe

those were filters youu must apply

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBogdan Gavril MSFTView Question on Stackoverflow
Solution 1 - WindowsGilles ArcasView Answer on Stackoverflow
Solution 2 - WindowsVinod SrivastavView Answer on Stackoverflow
Solution 3 - WindowsMullai NathanView Answer on Stackoverflow
Solution 4 - WindowsHobbe LundahlView Answer on Stackoverflow
Solution 5 - WindowsAliView Answer on Stackoverflow