如何将由find命令返回的文件列表传递给cat来查看所有文件 [英] How to pipe list of files returned by find command to cat to view all the files
问题描述
我正在做一个 find
,然后得到一个文件列表。如何将它传递给另一个实用程序,如 cat
(以便cat显示所有这些文件的内容),基本上需要 grep $ c
-
管道到另一个进程不会完成你所说的尝试):
command1 |命令2
这将发送command1的输出作为command2的输入
-
-exec
对一个find
(这会做你想要的做 - 但是特定于find
)find。 -name'* .foo'-exec cat {} \;
(
>
和-exec
是您已经使用的查找谓词,{}
会将您找到的特定文件替换为cat {}
);\;
结束-exec $ )
将一个进程的输出作为命令行参数发送给另一个进程
pre>command2`command1`
例如:
cat`find。 -name'* .foo'-print`
(注意这些是BACK-QUOTES不是普通的引号)
这将发送command1
到command2
的输出为命令行参数。请注意,包含空格(换行符等)的文件名将被分解为单独的参数。
I am doing a find
and then getting a list of files. How do I pipe it to another utility like cat
(so that cat displays the contents of all those files) and basically need to grep
something from these files.
Piping to another process (Although this WON'T accomplish what you said you are trying to do):
command1 | command2
This will send the output of command1 as the input of command2
-exec
on afind
(this will do what you are wanting to do -- but is specific tofind
)find . -name '*.foo' -exec cat {} \;
(Everything between
find
and-exec
are the find predicates you were already using.{}
will substitute the particular file you found into the command (cat {}
in this case); the\;
is to end the-exec
command.)send output of one process as command line arguments to another process
command2 `command1`
for example:
cat `find . -name '*.foo' -print`
(Note these are BACK-QUOTES not regular quotes (under the tilde ~ on my keyboard).) This will send the output of
command1
intocommand2
as command line arguments. Note that file names containing spaces (newlines, etc) will be broken into separate arguments, though.
这篇关于如何将由find命令返回的文件列表传递给cat来查看所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!