Findstr

findstr
其他名称qgrep
開發者Microsoft, ReactOS贡献者
操作系统Windows, ReactOS
平台跨平台
类型命令
许可协议Windows: 专有软件 商业软件
ReactOS: GNU通用公共许可证
网站docs.microsoft.com/en-us/windows-server/administration/windows-commands/findstr

findstr是Microsoft Windows[1][2]与ReactOS[3]命令行(即壳层)下用于在特定文件中搜索特定字符串的命令。[4]

概览

此命令将指定行发送到标准输出设备。[5] 它与find命令相似。然而,find命令支持UTF-16,而findstr不支持。另一方面,findstr支持正则表达式,但find不支持。 findstr最早在Windows 2000 Resource Kit下以名称qgrep发行。[6]

findstr无法搜索到Unicode文件中常见的空字符[7]

语法

FINDSTR flags strings [drive:][path]filename[...]

参数:

  • flags 下列选项的任意组合。
  • strings 搜索目标文本。
  • [drive:][path]filename 指定被搜索文件。

选项:

  • /B 匹配一行的开头。
  • /E 匹配一行的结尾。
  • /L 按原字符串搜索。
  • /R 按正则表达式搜索。
  • /S 在当前目录及所有子目录下搜索匹配文件。
  • /I 不区分大小写。
  • /X 输出严格匹配的行。
  • /V 仅输出不匹配的行。
  • /N 在所有匹配行前输出行号。
  • /M 仅当文件有至少一处匹配时输出文件名。
  • /O 在所有匹配行前输出字符偏移量。
  • /P 跳过含有不可打印字符的文件。
  • /OFF[LINE] 不要跳过有“离线”属性组的文件。
  • /A:attr 用两位十六进制数指定颜色属性(详见"color /?")。
  • /F:file 从指定文件获取被搜索文件(/ 表示直接读取自控制台)。
  • /C:string 将指定字符串按照原字符串搜索。
  • /G:file 从指定文件获取搜索目标文本(/ 表示直接读取自控制台)。
  • /D:dir 在半角冒号指定的目录列表下搜索。

注意: 下列命令显示此命令的详细帮助:

 FINDSTR /?

示例

将正在运行的服务保存到“_services.txt”文件,然后搜索文件中包含"network"的行(不区分大小写):

  @echo off
  set searchstr=network
  net start>_services.txt  
  FINDSTR /I "%searchstr%" _services.txt
  pause

输出是:

 Network Connections
 Network List Service
 Network Location Awareness
 Network Store Interface Service
 Windows Media Player Network Sharing Service
Press any key to continue . . .

另请参阅

維基教科書中的相關電子教程:Guide to Windows Commands

参考资料

  1. ^ Microsoft WinXP documentation for findstr. [2021-06-11]. (原始内容存档于2018-02-03). 
  2. ^ Microsoft Server 2012/2016 documentation for findstr. [2021-06-11]. (原始内容存档于2021-05-28). 
  3. ^ https://github.com/reactos/reactos/blob/master/base/applications/findstr/findstr.c
  4. ^ MS-DOS and Windows command line findstr command. [2021-06-11]. (原始内容存档于2021-06-11). 
  5. ^ Excellent documentation on usage of findstr. [2021-06-11]. (原始内容存档于2021-07-12). 
  6. ^ History of Findstr from Raymond Chen. [2021-06-11]. (原始内容存档于2015-11-21). 
  7. ^ Findstr - Search for strings - Windows CMD - SS64.com. [2021-06-11]. (原始内容存档于2021-06-11). 

更多

  • Stanek, William R. Windows Command-Line Administrator's Pocket Consultant, 2nd Edition. Microsoft Press. 2008. ISBN 978-0735622623. 
  • John Paul Mueller. Windows Administration at the Command Line for Windows Vista, Windows 2003, Windows XP, and Windows 2000. John Wiley & Sons. 2007. ISBN 978-0470165799. 

外部链接

文件管理导航
文件管理操作
  • attrib英语ATTRIB
  • cacls
  • cipher
  • compact
  • copy
  • del英语del (command) (erase)
  • deltree英语deltree
  • expand
  • icacls
  • makecab
  • md (mkdir)
  • move英语move (command)
  • rd (rmdir)
  • recover英语recover (command)
  • ren英语ren (command) (rename)
  • replace英语replace (command)
  • Rmdir
  • robocopy英语robocopy
  • xcopy英语XCOPY
磁盘管理
  • chkdsk
  • convert英语convert (command)
  • defrag
  • diskcomp英语diskcomp
  • diskcopy英语diskcopy
  • diskpart英语diskpart
  • fdisk英语fdisk
  • format英语Format (command)
  • label英语label (command)
  • subst英语SUBST
  • scandisk
  • sys英语SYS (command)
  • vol英语vol (command)
  • vssadmin
进程
  • exit
  • kill
  • powercfg英语powercfg
  • runas
  • sc
  • shutdown
  • start英语start (command)
  • taskkill
  • tasklist英语tasklist
注册表
用户环境
  • date
  • mode
  • path
  • set
  • setx
  • time英语TIME (command)
  • title
  • ver英语ver (command)
  • Whoami
文件内容
  • comp英语comp (command)
  • edit英语MS-DOS Editor
  • edlin英语edlin
  • fc英语Microsoft File Compare
  • find英语find (command)
  • findstr
  • print英语PRINT (command)
  • type英语TYPE (DOS command)
脚本
  • choice英语choice (command)
  • clip
  • cscript
  • doskey英语DOSKEY
  • echo
  • for
  • Goto
  • if
  • more
  • pause
  • prompt英语Command-line_interface#Command_prompt
  • rem
网络
维护
启动管理
软件开发
杂项
  • cls
  • help英语help (command)