Piping find into tar...

Chris Rees utisoft at gmail.com
Wed May 4 08:11:04 UTC 2011


On 4 May 2011 08:44, b. f. <bf1783 at googlemail.com> wrote:
>> I've been playing with the find command lately. Is there a way I can pipe the
>> putput list of files from find, into the tar command to create an archive which
>> contains the files which find lists? I tried the following, but it didn't work
>> (obviously).
>>
>> find -E . '.*\.txt$' -print | tar -cjf result.tgz
>
> You could use something like:
>
> find -X . -name '*.txt' | xargs tar -cjf result.tgz
>
> or
>
> find . -name '*.txt' -print0 | xargs -0 tar -cjf result.tgz
>
> b.

How about using pax?

find . -depth -print | pax -wd | gzip > archive.tgz

or

find . -depth -print | pax -wd | bzip2 > archive.tbz


By the way, in reference to the commands above the -j option is for
bzip2, so the extension should be .tbz o_O

Chris


More information about the freebsd-questions mailing list