如何将 find 命令返回的文件列表通过管道传输到 cat 以查看所有文件 [英] How to pipe list of files returned by find command to cat to view all the files

查看:49
本文介绍了如何将 find 命令返回的文件列表通过管道传输到 cat 以查看所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行 find 然后获取文件列表.我如何将它传送到另一个实用程序,例如 cat(以便 cat 显示所有这些文件的内容)并且基本上需要从这些文件中grep 一些东西.

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.

推荐答案

  1. 管道到另一个进程(虽然这不会完成你所说的你想要做的):

  1. Piping to another process (Although this WON'T accomplish what you said you are trying to do):

command1 | command2

这会将 command1 的输出作为 command2 的输入发送

This will send the output of command1 as the input of command2

-execfind 上(这会做你想做的事情——但特定于 find)

-exec on a find (this will do what you are wanting to do -- but is specific to find)

find . -name '*.foo' -exec cat {} ;

(find-exec 之间的所有内容都是您已经在使用的查找谓词.{} 将替换您找到的特定文件命令(在本例中为 cat {});; 用于结束 -exec 命令.)

(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`

例如:

cat `find . -name '*.foo' -print`

(注意这些是反引号而不是常规引号(在我键盘上的波浪号 ~ 下).)这会将 command1 的输出作为命令行参数发送到 command2 中.请注意,包含空格(换行符等)的文件名将被分解为单独的参数.

(Note these are BACK-QUOTES not regular quotes (under the tilde ~ on my keyboard).) This will send the output of command1 into command2 as command line arguments. Note that file names containing spaces (newlines, etc) will be broken into separate arguments, though.

这篇关于如何将 find 命令返回的文件列表通过管道传输到 cat 以查看所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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