windows 如何在cmd中进行简单的文件搜索

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8066679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:55:02  来源:igfitidea点击:

How to do a simple file search in cmd

windowscommand-linecmd

提问by Bogdan Gavril MSFT

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.

我想从 windows 命令行(不是 power shell)快速搜索给定名称或部分名称的文件。这类似于打开资源管理器并使用顶部的搜索框。

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

注意:dir可以基于字符串模板搜索,但不会在子目录中搜索。

Note2: findstrcan 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 ...

注2:findstr可用于在文件中搜索令牌并具有递归标志;有趣的是,可以轻松发现更复杂的发现......

回答by Gilles Arcas

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

dir /s *foo*在当前文件夹和子文件夹中搜索。

It finds directories as well as files.

它查找目录和文件。

回答by Vinod Srivastav

dir /b/s *.txt  

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

在目录树中搜索所有 txt 文件。在使用它之前,只需将目录更改为root使用

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 dircommand works since the old dos days but Win7 added something new called Where

编辑 1:虽然这个dir命令从旧的 dos 时代开始工作,但 Win7 添加了一些新的东西,叫做Where

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

will search for exe& dllin the drive c:\Windowsas suggested by @SPottuit you can also copy the output to the clipboard with

将按照@SPottuit 的建议在驱动器c:\Windows 中搜索exedll,您也可以将输出复制到剪贴板

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 moreto enable paging, it will show -- More --at the bottom and will scroll to the next page once you press SPACEor moves line by line on pressing ENTER

编辑 2:如果您正在递归搜索并且输出很大,您可以随时使用它more来启用分页,它将显示-- More --在底部,并在您按下SPACE或按行逐行移动后滚动到下一页ENTER

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

For more help try

如需更多帮助,请尝试

where/?

回答by Mullai Nathan

dir *.txt /s /pwill give more detailed information.

dir *.txt /s /p将提供更详细的信息。

回答by Hobbe Lundahl

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

DIR 的问题是它会返回错误的答案。如果您正在使用DIR *.DOC它在文件夹中查找 DOC,它也会为您提供DOCX。搜索*.HTM也会给出HTML等等...

回答by Ali

You can search in windows by DOS and explorer GUI.

您可以通过 DOS 和资源管理器 GUI 在 Windows 中搜索。

DOS:

操作系统:

1) DIR

1) 目录

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

2) ICACLS(搜索文件和文件夹以对其设置 ACL)

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

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

2) example

2) 例子

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

icacls c:*ntoskrnl*.* /grant system:(f) /c /t ,然后使用来自 sysinternals 的 PMON 来监控哪些文件夹被拒绝访问。结果包含

access path contains your drive

访问路径包含您的驱动器

process name is explorer.exe

进程名称是 explorer.exe

those were filters youu must apply

这些是您必须应用的过滤器