find与grep有什么区别? [英] What is the difference between find with grep?
问题描述
这些命令之间有什么区别:
What is the difference between these command:
find . –type f –name '*txt*'
和
find . –type f | grep 'txt'
我尝试运行此命令,但有区别,但是我想知道为什么吗?
I tried to run this and there is a difference but I want to know why?
推荐答案
主要区别是 FIND 用于使用过滤器搜索文件和目录,而 GREP 用于搜索文件内的模式或搜索过程
The Major difference is FIND is for searching files and directories using filters while GREP is for searching a pattern inside a file or searching process(es)
查找是使用大小,访问时间,修改时间等过滤器搜索文件和文件夹的命令。
find命令列出目录及其子目录中与一组过滤器匹配的所有文件。
此命令最常用于查找所有文件有一个特定的名称。
FIND is an command for searching file(s) and folder(s) using filters such as size , access time , modification time.
The find command lists all of the files within a directory and its sub-directories that match a set of filters.
This command is most commonly used to find all of the files that have a certain name.
要在当前目录及其所有子目录中找到所有名为theFile.txt的文件,请输入:
To find all of the files named theFile.txt in your current directory and all of its sub-directories, enter:
find . -name theFile.txt -print
要在当前目录及其子目录中查找所有以.txt扩展名结尾的文件,输入:
To look in your current directory and its sub-directories for all of the files that end in the extension .txt , enter:
find . -name "*.txt" -print
GREP :(全局搜索
在文件中搜索指定的字符串或表达式。
Searches files for a specified string or expression.
Grep搜索包含以下内容的行指定的模式,默认情况下将其写入标准输出。
Grep searches for lines containing a specified pattern and, by default, writes them to the standard output.
grep myText theFile.txt
结果:Grep将打印出包含单词 myText 的每一行。
Result : Grep will print out each line contain the word myText.
这篇关于find与grep有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!