find 和 grep 有什么区别? [英] What is the difference between find with grep?

查看:36
本文介绍了find 和 grep 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

What is the difference between these command:

find . –type f –name '*txt*' 

and

find . –type f | grep 'txt'

I tried to run this and there is a difference but I want to know why?

解决方案

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 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.

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

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 :(Globally search a Regular Expression and Print)

Searches files for a specified string or expression.

Grep searches for lines containing a specified pattern and, by default, writes them to the standard output.

grep myText theFile.txt

Result : Grep will print out each line contain the word myText.

这篇关于find 和 grep 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆