如何将由find命令返回的文件列表传递给cat来查看所有文件 [英] How to pipe list of files returned by find command to cat to view all the files

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

问题描述

我正在做一个 find ,然后得到一个文件列表。如何将它传递给另一个实用程序,如 cat (以便cat显示所有这些文件的内容),基本上需要 grep

解决方案


  1. 管道到另一个进程不会完成你所说的尝试):

      command1 |命令2 

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


  2. -exec 对一个 find (这会做你想要的做 - 但是特定于 find

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

    > -exec 是您已经使用的查找谓词, {} 会将您找到的特定文件替换为 cat {} ); \; 结束 -exec

  3. 将一个进程的输出作为命令行参数发送给另一个进程

    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.

解决方案

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

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

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

  3. 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 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天全站免登陆