Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 May 2011 08:04:16 -0500 (CDT)
From:      Robert Bonomi <bonomi@mail.r-bonomi.com>
To:        freebsd-questions@freebsd.org, modulok@gmail.com
Subject:   Re: Piping find into tar...
Message-ID:  <201105041304.p44D4Goi073793@mail.r-bonomi.com>
In-Reply-To: <BANLkTimNyNKADJ543wDcNBE=tWqjCCEw_w@mail.gmail.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
> From owner-freebsd-questions@freebsd.org  Wed May  4 02:26:32 2011
> Date: Wed, 4 May 2011 01:25:39 -0600
> From: Modulok <modulok@gmail.com>
> To: FreeBSD Questions <freebsd-questions@freebsd.org>
> Subject: Piping find into tar...
>
> List,
>
> 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're asking 'the wrong question'.  

tar _requires_ the filenames to  be listed as parameters to the command.

There are at least four ways to accomplish this, given the specific 
example you show.
 
1) The simplest: tar -cjf result.tbz .*.txt *.txt
2) in-line substitution: tar -cjf result.tbz `find -E . '.*\.txt$' -print` 
3) using the '-T' option:
     find -E . '.*\.txt$' -print0 | tar -c -j --null -T - -f result.tbz
3) using xargs:  
     find -E . '.*\.txt$' -print0 | xargs tar -rjf result.tar; bzip2 result.tar


Options 1) or 2) will fail 'immediately', if the pattern expands to an 
excessively long set of filenames.







Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?201105041304.p44D4Goi073793>