Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Dec 2001 00:39:01 -0500
From:      Simon Morton <simon.morton@verizon.net>
To:        FBSD Questions <questions@FreeBSD.ORG>
Subject:   Re: CP command format question
Message-ID:  <3C217975.10005@verizon.net>
References:  <LPBBIGIAAKKEOEJOLEGOKEONCJAA.barbish@a1poweruser.com>

next in thread | previous in thread | raw e-mail | index | archive | help
I am replying on the list because my mail directly to
barbish@a1poweruser.com bounced for some reason.

----

Joe & Fhe Barbish wrote:

Thanks for the response, but after the word custom on
the tar command you gave I have no idea what it means.
In need of some info on what it means and/or what it is doing.

----

So you know that "tar cf - custom" recursively writes the contents of
custom to the standard output as a tar archive stream.

"tar xf -" does the opposite; it reads a tar archive stream from
standard input and extracts its contents into the current directory.
The trick therefore is to cd from the source directory to the target
directory after starting the "tar cf" but before starting the "tar xf".

Hence:

tar cf - custom | (cd / ; tar xvf -)

(You can leave out one or both of the 'v's, all they do is generate 
verbose output.)

Why does this work?  When a stream is piped into a sequence of commands
enclosed in brackets, e.g.  ( A ; B ; C ), the first command in the 
sequence to open standard input consumes the entire stream (correct me
if I'm wrong someone but I think that's the rule.)

For example:

 > echo "foo" | (echo "bar" ; cat)
bar
foo

So, because "cd /" doesn't open standard input, it just changes the
working directory as a side effect but leaves the input stream alone
for "tar xf -".



Simon


-----Original Message-----
From: owner-freebsd-questions@FreeBSD.ORG
[mailto:owner-freebsd-questions@FreeBSD.ORG]On Behalf Of Simon Morton
Sent: Wednesday, December 19, 2001 1:33 PM
To: Joe & Fhe Barbish
Cc: FBSD Questions
Subject: Re: CP command format question

For recursive file tree copies, tar is your friend.

cd /a
tar cvf - custom | (cd /; tar xvf -)

Simon

Joe & Fhe Barbish wrote:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C217975.10005>