问题
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 ...
回答1:
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.
回答2:
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/?
回答3:
dir *.txt /s /p
will give more detailed information.
回答4:
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...
回答5:
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 ..................................................
2) 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
来源:https://stackoverflow.com/questions/8066679/how-to-do-a-simple-file-search-in-cmd