How to pipe list of files returned by find command to cat to view all the 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 want to do, but it’s 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 backquotes not regular quotes (they are under the tilde ~ on my keyboard).

    This will send the output of command1 into command2 as command line arguments. It’s called command substitution. Note that file names containing spaces (newlines, etc) will be broken into separate arguments, though.

Leave a Comment