Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pipe list of files returned by find command to cat to view all the files

Tags:

find

unix

pipe

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.

like image 681
Devang Kamdar Avatar asked Oct 07 '22 14:10

Devang Kamdar


People also ask

How do I see all files in a folder of cats?

You can use the * character to match all the files in your current directory. cat * will display the content of all the files.

Can the cat command be used to view multiple files?

Cat is short for concatenate. This command displays the contents of one or more files without having to open the file for editing.

Which Find command will display all the files which?

find –perm option is used to find files based upon permissions. You can use find –perm 444 to get all files that allow read permission to the owner, group, and others.


1 Answers

  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.

like image 133
kenj0418 Avatar answered Oct 24 '22 23:10

kenj0418