[CLUG-tech] recursive tar

Michael Wood michael.wood at uct.ac.za
Fri Mar 9 10:49:57 SAST 2007


On Thu, Mar 08, 2007 at 11:07:08PM +0200, Izak Burger wrote:
> On 3/8/07, Jeremy Thurgood <jerith at jerith.za.net> wrote:
> >Looks like a job for find:
> 
> Agreed.  Everyone seems to forget about the tar -T option though (-T-
> makes it read the list from stdin, pretty much like cpio does):
> 
> find . -name "*.prj" | tar -T- -zcf /home/data/tarzGW0_`date +%Y%m%d`

I know the following situation is not likely, but the above will
break if you have newlines in your filenames.

e.g.:

$ mkdir /tmp/tartest
$ cd /tmp/tartest
$ touch "`echo -en 'test\nblah.prj'`"
$ find . -name "*.prj" | tar -T- -zcf test.tar.gz
tar: ./test: Cannot stat: No such file or directory
tar: blah.prj: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
$ 

But this will fix it:

$ find . -name "*.prj" -print0 | tar --null -T- -zcf test.tar.gz
$ tar tzf test.tar.gz
./test\nblah.prj

-- 
Michael Wood <michael.wood at uct.ac.za>


More information about the clug-tech mailing list