Linux命令:如何只“查找”文本文件?

时间:2022-08-29 22:57:09

After a few searches from Google, what I come up with is:

在谷歌上搜索了几次之后,我想到的是:

find my_folder -type f -exec grep -l "needle text" {} \; -exec file {} \; | grep text

which is very unhandy and outputs unneeded texts such as mime type information. Any better solutions? I have lots of images and other binary files in the same folder with a lot of text files that I need to search through.

这非常不方便,并且输出不需要的文本,如mime类型信息。更好的解决方案吗?我在同一个文件夹中有很多图片和其他二进制文件,还有很多文本文件需要搜索。

14 个解决方案

#1


121  

I know this is an old thread, but I stumbled across it and thought I'd share my method which I have found to be a very fast way to use find to find only non-binary files:

我知道这是一个旧的线程,但我偶然发现它,并认为我将分享我的方法,我发现这是一种非常快速的方法,使用查找来查找非二进制文件:

find . -type f -exec grep -Iq . {} \; -and -print

The -I option to grep tells it to immediately ignore binary files and the . option along with the -q will make it immediately match text files so it goes very fast. You can change the -print to a -print0 for piping into an xargs -0 or something if you are concerned about spaces (thanks for the tip, @lucas.werkmeister!)

grep的-I选项告诉它立即忽略二进制文件和。选项连同-q将使它立即匹配文本文件,因此它运行得非常快。如果您关心空间的话,您可以将管道的-print更改为-print0 (@lucas.werkmeister)。

Also the first dot is only necessary for certain BSD versions of find such as on OS X, but it doesn't hurt anything just having it there all the time if you want to put this in an alias or something.

第一个点对于某些BSD版本来说是必要的,比如在OS X上,但是如果你想把它放在一个别名中,它不会伤害任何东西。

#2


10  

Why is it unhandy? If you need to use it often, and don't want to type it every time just define a bash function for it:

为什么它是不方便的?如果您需要经常使用它,并且不想每次都输入它,只需为它定义一个bash函数:

function findTextInAsciiFiles {
    # usage: findTextInAsciiFiles DIRECTORY NEEDLE_TEXT
    find "$1" -type f -exec grep -l "$2" {} \; -exec file {} \; | grep text
}

put it in your .bashrc and then just run:

把它放在你的。bashrc中,然后运行:

findTextInAsciiFiles your_folder "needle text"

whenever you want.

每当你想要的。


EDIT to reflect OP's edit:

编辑以反映OP的编辑:

if you want to cut out mime informations you could just add a further stage to the pipeline that filters out mime informations. This should do the trick, by taking only what comes before :: cut -d':' -f1:

如果您想要删除mime信息,您可以向过滤mime信息的管道添加一个进一步的阶段。这应该会起到作用,只取之前的::cut -d':' -f1:

function findTextInAsciiFiles {
    # usage: findTextInAsciiFiles DIRECTORY NEEDLE_TEXT
    find "$1" -type f -exec grep -l "$2" {} \; -exec file {} \; | grep text | cut -d ':' -f1
}

#3


8  

Based on this SO question :

基于这个SO问题:

grep -rIl "needle text" my_folder

grep -rIl“指针文本”my_folder。

#4


4  

find . -type f -print0 | xargs -0 file | grep -P text | cut -d: -f1 | xargs grep -Pil "search"

This is unfortunately not space save. Putting this into bash script makes it a bit easier.

不幸的是,这并不是节省空间。把这个放到bash脚本中会使它更容易一些。

This is space safe:

这是空间安全:

#!/bin/bash
#if [ ! "$1" ] ; then
    echo "Usage: $0 <search>";
    exit
fi

find . -type f -print0 \
  | xargs -0 file \
  | grep -P text \
  | cut -d: -f1 \
  | xargs -i% grep -Pil "$1" "%"

#5


2  

How about this:

这个怎么样:

$ grep -rl "needle text" my_folder | tr '\n' '\0' | xargs -r -0 file | grep -e ':[^:]*text[^:]*$' | grep -v -e 'executable'

If you want the filenames without the file types, just add a final sed filter.

如果希望文件名不包含文件类型,只需添加最终的sed过滤器。

$ grep -rl "needle text" my_folder | tr '\n' '\0' | xargs -r -0 file | grep -e ':[^:]*text[^:]*$' | grep -v -e 'executable' | sed 's|:[^:]*$||'

You can filter-out unneeded file types by adding more -e 'type' options to the last grep command.

您可以通过在最后一个grep命令中添加更多-e 'type'选项来过滤不需要的文件类型。

EDIT:

编辑:

If your xargs version supports the -d option, the commands above become simpler:

如果您的xargs版本支持-d选项,上面的命令将变得更简单:

$ grep -rl "needle text" my_folder | xargs -d '\n' -r file | grep -e ':[^:]*text[^:]*$' | grep -v -e 'executable' | sed 's|:[^:]*$||'

#6


2  

Here's how I've done it ...

我是这样做的……

1 . make a small script to test if a file is plain text istext:

1。编写一个小脚本,测试文件是否为纯文本istext:

#!/bin/bash
[[ "$(file -bi $1)" == *"file"* ]]

2 . use find as before

2。使用之前找到

find . -type f -exec istext {} \; -exec grep -nHi mystring {} \;

#7


2  

I have two issues with histumness' answer:

我对histumness的回答有两个问题:

  • It only list text files. It does not actually search them as requested. To actually search, use

    它只列出文本文件。它实际上并没有按要求搜索它们。搜索,使用

    find . -type f -exec grep -Iq . {} \; -and -print0 | xargs -0 grep "needle text"
    
  • It spawns a grep process for every file, which is very slow. A better solution is then

    它为每个文件生成一个grep进程,速度非常慢。一个更好的解决办法就是

    find . -type f -print0 | xargs -0 grep -IZl . | xargs -0 grep "needle text"
    

    or simply

    或者简单地

    find . -type f -print0 | xargs -0 grep -I "needle text"
    

    This only takes 0.2s compared to 4s for solution above (2.5GB data / 7700 files), i.e. 20x faster.

    与上面的4s解决方案(2.5GB数据/ 7700个文件)相比,这只需要0.2s,即速度快20倍。

Also, nobody cited ag, the Silver Searcher or ack-grep¸as alternatives. If one of these are available, they are much better alternatives:

也没人提到ag)银搜索者或ack-grep¸作为替代品。如果其中有一个是可用的,那么它们是更好的选择:

ag -t "needle text"    # Much faster than ack
ack -t "needle text"   # or ack-grep

As a last note, beware of false positives (binary files taken as text files). I already had false positive using either grep/ag/ack, so better list the matched files first before editing the files.

最后要注意的是,要小心误报(二进制文件作为文本文件)。我已经在使用grep/ag/ack时得到了假阳性,所以最好在编辑文件之前先列出匹配的文件。

#8


1  

Although it is an old question, I think this info bellow will add to the quality of the answers here.

虽然这是一个老问题,但我认为这个信息会增加答案的质量。

When ignoring files with the executable bit set, I just use this command:

当使用可执行位集忽略文件时,我只使用以下命令:

find . ! -perm -111

To keep it from recursively enter into other directories:

为了防止它递归地进入其他目录:

find . -maxdepth 1 ! -perm -111

No need for pipes to mix lots of commands, just the powerful plain find command.

不需要管道混合许多命令,只需强大的plain find命令。

  • Disclaimer: it is not exactly what OP asked, because it doesn't check if the file is binary or not. It will, for example, filter out bash script files, that are text themselves but have the executable bit set.
  • 声明:这不是OP所要求的,因为它不检查文件是否为二进制文件。例如,它将过滤掉bash脚本文件,这些文件本身就是文本,但是具有可执行位集。

That said, I hope this is useful to anyone.

也就是说,我希望这对任何人都有用。

#9


1  

Another way of doing this:

另一种方法是:

# find . |xargs file {} \; |grep "ASCII text"

If you want empty files too:

如果你也想要空文件:

#  find . |xargs file {} \; |egrep "ASCII text|empty"

#10


0  

I do it this way: 1) since there're too many files (~30k) to search thru, I generate the text file list daily for use via crontab using below command:

我是这样做的:1)由于有太多的文件(~30k)需要搜索,所以我每天都会生成文本文件列表,通过crontab使用下面的命令:

find /to/src/folder -type f -exec file {} \; | grep text | cut -d: -f1 > ~/.src_list &

2) create a function in .bashrc:

2)在。bashrc中创建一个函数:

findex() {
    cat ~/.src_list | xargs grep "$*" 2>/dev/null
}

Then I can use below command to do the search:

然后我可以使用下面的命令进行搜索:

findex "needle text"

HTH:)

HTH:)

#11


0  

I prefer xargs

我更喜欢xargs

find . -type f | xargs grep -I "needle text"

if your filenames are weird look up using the -0 options:

如果你的文件名很奇怪,用-0选项查找:

find . -type f -print0 | xargs -0 grep -I "needle text"

#12


0  

  • bash example to serach text "eth0" in /etc in all text/ascii files
  • 用bash示例在所有文本/ascii文件中/等中serach文本“eth0”

grep eth0 $(find /etc/ -type f -exec file {} \; | egrep -i "text|ascii" | cut -d ':' -f1)

grep eth0 $(查找/etc/ -type f -exec file {} \;|白鹭-i "text|ascii" | cut -d ':' -f1)

#13


0  

Here's a simplified version with extended explanation for beginners like me who are trying to learn how to put more than one command in one line.

这是一个简化版,对于像我这样的初学者来说,他们正在尝试学习如何在一行中添加多个命令。

If you were to write out the problem in steps, it would look like this:

如果你把问题一步一步地写出来,它会是这样的:

// For every file in this directory
// Check the filetype
// If it's an ASCII file, then print out the filename

To achieve this, we can use three UNIX commands: find, file, and grep.

为此,我们可以使用三个UNIX命令:find、file和grep。

find will check every file in the directory.

查找将检查目录中的每个文件。

file will give us the filetype. In our case, we're looking for a return of 'ASCII text'

文件将给我们文件类型。在我们的例子中,我们在寻找返回的" ASCII文本"

grep will look for the keyword 'ASCII' in the output from file

grep将在文件的输出中查找关键字“ASCII”

So how can we string these together in a single line? There are multiple ways to do it, but I find that doing it in order of our pseudo-code makes the most sense (especially to a beginner like me).

所以我们如何这些在一行字符串?有多种方法去做,但是我发现这样做为了我们的伪代码最意义(特别是像我这样的初学者)。

find ./ -exec file {} ";" | grep 'ASCII'

找到。/ - exec文件{ }”;“| grep“ASCII”

Looks complicated, but not bad when we break it down:

看起来很复杂,但分解的时候还不错:

find ./ = look through every file in this directory. The find command prints out the filename of any file that matches the 'expression', or whatever comes after the path, which in our case is the current directory or ./

查找该目录中的每个文件。find命令输出与“expression”匹配的任何文件的文件名,或路径后面的任何文件,在我们的例子中,路径是当前目录或./

The most important thing to understand is that everything after that first bit is going to be evaluated as either True or False. If True, the file name will get printed out. If not, then the command moves on.

需要理解的最重要的一点是,第一个比特之后的所有东西都将被评估为真或假。如果是,文件名将被打印出来。如果不是,那么在前进的命令。

-exec = this flag is an option within the find command that allows us to use the result of some other command as the search expression. It's like calling a function within a function.

-exec =此标志是find命令中的一个选项,允许我们使用其他命令的结果作为搜索表达式。就像在函数中调用一个函数。

file {} = the command being called inside of find. The file command returns a string that tells you the filetype of a file. Regularly, it would look like this: file mytextfile.txt. In our case, we want it to use whatever file is being looked at by the find command, so we put in the curly braces {} to act as an empty variable, or parameter. In other words, we're just asking for the system to output a string for every file in the directory.

file {} = find内部调用的命令。文件命令返回一个字符串,该字符串告诉您文件的filetype。通常,它看起来是这样的:文件mytextfile.txt。在我们的示例中,我们希望它使用find命令正在查看的任何文件,因此我们在花括号{}中作为一个空变量或参数。换句话说,我们只是要求系统为目录中的每个文件输出一个字符串。

";" = this is required by find and is the punctuation mark at the end of our -exec command. See the manual for 'find' for more explanation if you need it by running man find.

”;“=这是需要发现和标点符号的我们- exec命令。如果你需要更多的解释,请参阅“查找”手册。

| grep 'ASCII' = | is a pipe. Pipe take the output of whatever is on the left and uses it as input to whatever is on the right. It takes the output of the find command (a string that is the filetype of a single file) and tests it to see if it contains the string 'ASCII'. If it does, it returns true.

| grep 'ASCII' = |是一个管道。管无论在左边的输出和使用它作为输入任何在右边。它获取find命令的输出(一个字符串是单个文件的文件类型),并测试它是否包含字符串'ASCII'。如果是,则返回true。

NOW, the expression to the right of find ./ will return true when the grep command returns true. Voila.

现在,表达式的右边找到。/将返回true grep命令时返回true。瞧。

#14


-3  

How about this

这个怎么样

 find . -type f|xargs grep "needle text"

#1


121  

I know this is an old thread, but I stumbled across it and thought I'd share my method which I have found to be a very fast way to use find to find only non-binary files:

我知道这是一个旧的线程,但我偶然发现它,并认为我将分享我的方法,我发现这是一种非常快速的方法,使用查找来查找非二进制文件:

find . -type f -exec grep -Iq . {} \; -and -print

The -I option to grep tells it to immediately ignore binary files and the . option along with the -q will make it immediately match text files so it goes very fast. You can change the -print to a -print0 for piping into an xargs -0 or something if you are concerned about spaces (thanks for the tip, @lucas.werkmeister!)

grep的-I选项告诉它立即忽略二进制文件和。选项连同-q将使它立即匹配文本文件,因此它运行得非常快。如果您关心空间的话,您可以将管道的-print更改为-print0 (@lucas.werkmeister)。

Also the first dot is only necessary for certain BSD versions of find such as on OS X, but it doesn't hurt anything just having it there all the time if you want to put this in an alias or something.

第一个点对于某些BSD版本来说是必要的,比如在OS X上,但是如果你想把它放在一个别名中,它不会伤害任何东西。

#2


10  

Why is it unhandy? If you need to use it often, and don't want to type it every time just define a bash function for it:

为什么它是不方便的?如果您需要经常使用它,并且不想每次都输入它,只需为它定义一个bash函数:

function findTextInAsciiFiles {
    # usage: findTextInAsciiFiles DIRECTORY NEEDLE_TEXT
    find "$1" -type f -exec grep -l "$2" {} \; -exec file {} \; | grep text
}

put it in your .bashrc and then just run:

把它放在你的。bashrc中,然后运行:

findTextInAsciiFiles your_folder "needle text"

whenever you want.

每当你想要的。


EDIT to reflect OP's edit:

编辑以反映OP的编辑:

if you want to cut out mime informations you could just add a further stage to the pipeline that filters out mime informations. This should do the trick, by taking only what comes before :: cut -d':' -f1:

如果您想要删除mime信息,您可以向过滤mime信息的管道添加一个进一步的阶段。这应该会起到作用,只取之前的::cut -d':' -f1:

function findTextInAsciiFiles {
    # usage: findTextInAsciiFiles DIRECTORY NEEDLE_TEXT
    find "$1" -type f -exec grep -l "$2" {} \; -exec file {} \; | grep text | cut -d ':' -f1
}

#3


8  

Based on this SO question :

基于这个SO问题:

grep -rIl "needle text" my_folder

grep -rIl“指针文本”my_folder。

#4


4  

find . -type f -print0 | xargs -0 file | grep -P text | cut -d: -f1 | xargs grep -Pil "search"

This is unfortunately not space save. Putting this into bash script makes it a bit easier.

不幸的是,这并不是节省空间。把这个放到bash脚本中会使它更容易一些。

This is space safe:

这是空间安全:

#!/bin/bash
#if [ ! "$1" ] ; then
    echo "Usage: $0 <search>";
    exit
fi

find . -type f -print0 \
  | xargs -0 file \
  | grep -P text \
  | cut -d: -f1 \
  | xargs -i% grep -Pil "$1" "%"

#5


2  

How about this:

这个怎么样:

$ grep -rl "needle text" my_folder | tr '\n' '\0' | xargs -r -0 file | grep -e ':[^:]*text[^:]*$' | grep -v -e 'executable'

If you want the filenames without the file types, just add a final sed filter.

如果希望文件名不包含文件类型,只需添加最终的sed过滤器。

$ grep -rl "needle text" my_folder | tr '\n' '\0' | xargs -r -0 file | grep -e ':[^:]*text[^:]*$' | grep -v -e 'executable' | sed 's|:[^:]*$||'

You can filter-out unneeded file types by adding more -e 'type' options to the last grep command.

您可以通过在最后一个grep命令中添加更多-e 'type'选项来过滤不需要的文件类型。

EDIT:

编辑:

If your xargs version supports the -d option, the commands above become simpler:

如果您的xargs版本支持-d选项,上面的命令将变得更简单:

$ grep -rl "needle text" my_folder | xargs -d '\n' -r file | grep -e ':[^:]*text[^:]*$' | grep -v -e 'executable' | sed 's|:[^:]*$||'

#6


2  

Here's how I've done it ...

我是这样做的……

1 . make a small script to test if a file is plain text istext:

1。编写一个小脚本,测试文件是否为纯文本istext:

#!/bin/bash
[[ "$(file -bi $1)" == *"file"* ]]

2 . use find as before

2。使用之前找到

find . -type f -exec istext {} \; -exec grep -nHi mystring {} \;

#7


2  

I have two issues with histumness' answer:

我对histumness的回答有两个问题:

  • It only list text files. It does not actually search them as requested. To actually search, use

    它只列出文本文件。它实际上并没有按要求搜索它们。搜索,使用

    find . -type f -exec grep -Iq . {} \; -and -print0 | xargs -0 grep "needle text"
    
  • It spawns a grep process for every file, which is very slow. A better solution is then

    它为每个文件生成一个grep进程,速度非常慢。一个更好的解决办法就是

    find . -type f -print0 | xargs -0 grep -IZl . | xargs -0 grep "needle text"
    

    or simply

    或者简单地

    find . -type f -print0 | xargs -0 grep -I "needle text"
    

    This only takes 0.2s compared to 4s for solution above (2.5GB data / 7700 files), i.e. 20x faster.

    与上面的4s解决方案(2.5GB数据/ 7700个文件)相比,这只需要0.2s,即速度快20倍。

Also, nobody cited ag, the Silver Searcher or ack-grep¸as alternatives. If one of these are available, they are much better alternatives:

也没人提到ag)银搜索者或ack-grep¸作为替代品。如果其中有一个是可用的,那么它们是更好的选择:

ag -t "needle text"    # Much faster than ack
ack -t "needle text"   # or ack-grep

As a last note, beware of false positives (binary files taken as text files). I already had false positive using either grep/ag/ack, so better list the matched files first before editing the files.

最后要注意的是,要小心误报(二进制文件作为文本文件)。我已经在使用grep/ag/ack时得到了假阳性,所以最好在编辑文件之前先列出匹配的文件。

#8


1  

Although it is an old question, I think this info bellow will add to the quality of the answers here.

虽然这是一个老问题,但我认为这个信息会增加答案的质量。

When ignoring files with the executable bit set, I just use this command:

当使用可执行位集忽略文件时,我只使用以下命令:

find . ! -perm -111

To keep it from recursively enter into other directories:

为了防止它递归地进入其他目录:

find . -maxdepth 1 ! -perm -111

No need for pipes to mix lots of commands, just the powerful plain find command.

不需要管道混合许多命令,只需强大的plain find命令。

  • Disclaimer: it is not exactly what OP asked, because it doesn't check if the file is binary or not. It will, for example, filter out bash script files, that are text themselves but have the executable bit set.
  • 声明:这不是OP所要求的,因为它不检查文件是否为二进制文件。例如,它将过滤掉bash脚本文件,这些文件本身就是文本,但是具有可执行位集。

That said, I hope this is useful to anyone.

也就是说,我希望这对任何人都有用。

#9


1  

Another way of doing this:

另一种方法是:

# find . |xargs file {} \; |grep "ASCII text"

If you want empty files too:

如果你也想要空文件:

#  find . |xargs file {} \; |egrep "ASCII text|empty"

#10


0  

I do it this way: 1) since there're too many files (~30k) to search thru, I generate the text file list daily for use via crontab using below command:

我是这样做的:1)由于有太多的文件(~30k)需要搜索,所以我每天都会生成文本文件列表,通过crontab使用下面的命令:

find /to/src/folder -type f -exec file {} \; | grep text | cut -d: -f1 > ~/.src_list &

2) create a function in .bashrc:

2)在。bashrc中创建一个函数:

findex() {
    cat ~/.src_list | xargs grep "$*" 2>/dev/null
}

Then I can use below command to do the search:

然后我可以使用下面的命令进行搜索:

findex "needle text"

HTH:)

HTH:)

#11


0  

I prefer xargs

我更喜欢xargs

find . -type f | xargs grep -I "needle text"

if your filenames are weird look up using the -0 options:

如果你的文件名很奇怪,用-0选项查找:

find . -type f -print0 | xargs -0 grep -I "needle text"

#12


0  

  • bash example to serach text "eth0" in /etc in all text/ascii files
  • 用bash示例在所有文本/ascii文件中/等中serach文本“eth0”

grep eth0 $(find /etc/ -type f -exec file {} \; | egrep -i "text|ascii" | cut -d ':' -f1)

grep eth0 $(查找/etc/ -type f -exec file {} \;|白鹭-i "text|ascii" | cut -d ':' -f1)

#13


0  

Here's a simplified version with extended explanation for beginners like me who are trying to learn how to put more than one command in one line.

这是一个简化版,对于像我这样的初学者来说,他们正在尝试学习如何在一行中添加多个命令。

If you were to write out the problem in steps, it would look like this:

如果你把问题一步一步地写出来,它会是这样的:

// For every file in this directory
// Check the filetype
// If it's an ASCII file, then print out the filename

To achieve this, we can use three UNIX commands: find, file, and grep.

为此,我们可以使用三个UNIX命令:find、file和grep。

find will check every file in the directory.

查找将检查目录中的每个文件。

file will give us the filetype. In our case, we're looking for a return of 'ASCII text'

文件将给我们文件类型。在我们的例子中,我们在寻找返回的" ASCII文本"

grep will look for the keyword 'ASCII' in the output from file

grep将在文件的输出中查找关键字“ASCII”

So how can we string these together in a single line? There are multiple ways to do it, but I find that doing it in order of our pseudo-code makes the most sense (especially to a beginner like me).

所以我们如何这些在一行字符串?有多种方法去做,但是我发现这样做为了我们的伪代码最意义(特别是像我这样的初学者)。

find ./ -exec file {} ";" | grep 'ASCII'

找到。/ - exec文件{ }”;“| grep“ASCII”

Looks complicated, but not bad when we break it down:

看起来很复杂,但分解的时候还不错:

find ./ = look through every file in this directory. The find command prints out the filename of any file that matches the 'expression', or whatever comes after the path, which in our case is the current directory or ./

查找该目录中的每个文件。find命令输出与“expression”匹配的任何文件的文件名,或路径后面的任何文件,在我们的例子中,路径是当前目录或./

The most important thing to understand is that everything after that first bit is going to be evaluated as either True or False. If True, the file name will get printed out. If not, then the command moves on.

需要理解的最重要的一点是,第一个比特之后的所有东西都将被评估为真或假。如果是,文件名将被打印出来。如果不是,那么在前进的命令。

-exec = this flag is an option within the find command that allows us to use the result of some other command as the search expression. It's like calling a function within a function.

-exec =此标志是find命令中的一个选项,允许我们使用其他命令的结果作为搜索表达式。就像在函数中调用一个函数。

file {} = the command being called inside of find. The file command returns a string that tells you the filetype of a file. Regularly, it would look like this: file mytextfile.txt. In our case, we want it to use whatever file is being looked at by the find command, so we put in the curly braces {} to act as an empty variable, or parameter. In other words, we're just asking for the system to output a string for every file in the directory.

file {} = find内部调用的命令。文件命令返回一个字符串,该字符串告诉您文件的filetype。通常,它看起来是这样的:文件mytextfile.txt。在我们的示例中,我们希望它使用find命令正在查看的任何文件,因此我们在花括号{}中作为一个空变量或参数。换句话说,我们只是要求系统为目录中的每个文件输出一个字符串。

";" = this is required by find and is the punctuation mark at the end of our -exec command. See the manual for 'find' for more explanation if you need it by running man find.

”;“=这是需要发现和标点符号的我们- exec命令。如果你需要更多的解释,请参阅“查找”手册。

| grep 'ASCII' = | is a pipe. Pipe take the output of whatever is on the left and uses it as input to whatever is on the right. It takes the output of the find command (a string that is the filetype of a single file) and tests it to see if it contains the string 'ASCII'. If it does, it returns true.

| grep 'ASCII' = |是一个管道。管无论在左边的输出和使用它作为输入任何在右边。它获取find命令的输出(一个字符串是单个文件的文件类型),并测试它是否包含字符串'ASCII'。如果是,则返回true。

NOW, the expression to the right of find ./ will return true when the grep command returns true. Voila.

现在,表达式的右边找到。/将返回true grep命令时返回true。瞧。

#14


-3  

How about this

这个怎么样

 find . -type f|xargs grep "needle text"