From owner-freebsd-questions@FreeBSD.ORG Wed May 4 13:04:05 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 823041065670 for ; Wed, 4 May 2011 13:04:05 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (mx-out.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id 59DB08FC08 for ; Wed, 4 May 2011 13:04:04 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id p44D4Goi073793; Wed, 4 May 2011 08:04:16 -0500 (CDT) Date: Wed, 4 May 2011 08:04:16 -0500 (CDT) From: Robert Bonomi Message-Id: <201105041304.p44D4Goi073793@mail.r-bonomi.com> To: freebsd-questions@freebsd.org, modulok@gmail.com In-Reply-To: Cc: Subject: Re: Piping find into tar... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2011 13:04:05 -0000 > From owner-freebsd-questions@freebsd.org Wed May 4 02:26:32 2011 > Date: Wed, 4 May 2011 01:25:39 -0600 > From: Modulok > To: FreeBSD Questions > 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.