How to perform a simple file search in cmd

I want to quickly find a file by its name or part of the name on the Windows command line (not in Power Shell). This is similar to opening the explorer and using the search box at the top.

Note: dir can search based on a string pattern, but will not search in subdirectories.

Note 2: findstr can be used to search for a token inside files and has a recursive flag; funny that a more complex find can be easily detected ...

+94
command-line windows cmd
Nov 09 2018-11-11T00:
source share
5 answers

dir/s *foo* searches the current folder and subfolders.

It finds directories as well as files.

+121
Nov 09 2018-11-11T00:
source share
 dir /b/s *.txt 

Searches for all text files in the directory tree. Before use, just change the directory to root with

 cd/ 

You can also export the list to a text file using

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

and search using

 type filelist.txt | find /n "filename" 

EDIT 1: Although this dir command has been working since the old days, but Win7 added something new called Where

 where /rc:\Windows *.exe *.dll 

will look for exe & dll on the c: \ Windows drive , as suggested by @SPottuit, you can also copy the output to the clipboard using

 where /rc:\Windows *.exe |clip 

just wait for the invitation and do not copy anything until then.

EDIT 2: If you are looking for a recursive search, and the result is large, you can always use more to enable swapping, it will show -- More -- at the bottom and will go to the next page when you press SPACE or move line by line by pressing ENTER

 where /rc:\Windows *.exe |more 

For more help, try

 where/? 
+99
Sep 08 '14 at 4:33
source share

dir *.txt/s/p will provide more details.

+2
Apr 26 '18 at 5:00
source share

The problem with DIR is that it will return incorrect answers. If you search for DOC in a folder using DIR *.DOC it will also give you DOCX . A *.HTM search *.HTM also give HTML and so on ...

0
Feb 10 '19 at 7:01
source share

You can search in Windows for DOS and GUI Explorer.

DOS:

1) DIR

2) ICACLS (looks for files and folders to set ACLs on them)

3) cacls ............................................... ...

2) example

icacls c: * ntoskrnl *. * / grant system: (f) / c / t, then use sysinternals PMON to track which folders are denied access. Result contains

access path contains your drive

process name - explorer.exe

these were the filters you should apply

0
Apr 27 '19 at 22:01
source share



All Articles