find
小猪老师 发表于 2020-06-22 16:29浏览次数:
使用find命令可以在文件中搜索文本。尽管MS-DOS不区分大小写,但在键入字符串时,您需要确保使用正确的大小写。
此外,此命令用于在文件中查找文本,而不是实际文件本身。如果要搜索或查找具有特定名称的文件,请使用dir命令。
The find command allows you to search for text within a file. Although MS-DOS is not case-sensitive, when typing in the string, you'll need to make sure that you're using the correct case.
Additionally, this command is used to find text within a file, not the actual file itself. If you want to search or find a file with a particular name, use the dir command.
如果您使用的是Windows XP或更高版本,请考虑使用改进的findstr命令。
If you're running Windows XP or later, consider using the improved findstr command.
目录:
1 find 运行系统环境
2 find 语法
3 find 示例
find 运行系统环境
Windows 95
Windows 98
Windows xp
Windows vista
Windows 2000
Windows 7
Windows 8
Windows 10
Windows NT
Windows ME
All Versions of MS-DOS
find 语法
Windows Vista 和更高版本的语法
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]file name[ ...]]
/V
|
显示不包含指定字符串的所有行。
|
/C
|
只显示包含该字符串的行数。
|
/N
|
与所显示的行一起显示行号。
|
/I
|
在搜索字符串时忽略字符的大小写。
|
/OFF[LINE]
|
不要跳过设置了脱机属性的文件。
|
"string"
|
指定要查找的文本字符串。
|
[drive:][path]file name
|
指定要搜索的一个或多个文件。
|
如果未指定路径名,FIND将搜索在提示符处输入的文本或从另一个命令通过管道输入的文本。
Windows XP和以前的语法
FIND [/V] [/C] [/N] [/I] "string" [[drive:][path]file name[ ...]]
/V
|
显示不包含指定字符串的所有行。
|
/C
|
只显示包含该字符串的行数。
|
/N
|
与所显示的行一起显示行号。
|
/I
|
在搜索字符串时忽略字符的大小写。
|
"string"
|
指定要查找的文本字符串。
|
[drive:][path]file name
|
指定要搜索的一个或多个文件
|
如果未指定路径名,FIND将搜索在提示符处输入的文本或从另一个命令通过管道输入的文本。
Windows Vista and later syntax
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]file name[ ...]]
/V
|
Displays all lines NOT containing the specified string.
|
/C
|
Displays only the count of lines containing the string.
|
/N
|
Displays line numbers with the displayed lines.
|
/I
|
Ignores the case of characters when searching for the string.
|
/OFF[LINE]
|
Do not skip files with offline attribute set.
|
"string"
|
Specifies the text string to find.
|
[drive:][path]file name
|
Specifies a file or files to search.
|
If a pathname is not specified, FIND searches the text typed at the prompt or piped from another command.
Windows XP and earlier syntax
FIND [/V] [/C] [/N] [/I] "string" [[drive:][path]file name[ ...]]
/V
|
Displays all lines NOT containing the specified string.
|
/C
|
Displays only the count of lines containing the string.
|
/N
|
Displays line numbers with the displayed lines.
|
/I
|
Ignores the case of characters when searching for the string.
|
"string"
|
Specifies the text string to find.
|
[drive:][path]file name
|
Specifies a file or files to search.
|
If a pathname is not specified, FIND searches the text typed at the prompt or piped from another command.
find 示例
find /c "REM" c:\autoexec.bat
上面的示例将在autoexecute .bat中找到任何“REM”语句。
find /v /c "&*fake&*" programs.txt
列出不包含"&*fake&* "的每一行,因为任何文件都不可能包含这个文本字符串,这将给您一个文件的准确行数。
find "hope" *.txt
下一个示例在当前目录中搜索包含希望文本的任何文本文件(.txt)。从下面的输出中可以看到,唯一包含hope的文件是CH.TXT文件。
---------- ACTIVE SETUP LOG.TXT
---------- CH.TXT
computer hope
---------- MODEMDET.TXT
---------- OEWABLOG.TXT
---------- SCHEDLGU.TXT
---------- SETUPLOG.TXT
find /c "REM" c:\autoexec.bat
The example above would find any "REM" statement in the autoexec.bat.
find /v /c "&*fake&*" programs.txt
List each line not containing "&*fake&*," because it's very unlikely that any file would containing this string of text this would give you an accurate line count of the file.
find "hope" *.txt
The next example searches for any text file (.txt) that contains the text hope in the current directory. As can be seen in the output below, the only file that contains hope is the CH.TXT file.
---------- ACTIVE SETUP LOG.TXT
---------- CH.TXT
computer hope
---------- MODEMDET.TXT
---------- OEWABLOG.TXT
---------- SCHEDLGU.TXT
---------- SETUPLOG.TXT