From owner-freebsd-questions@FreeBSD.ORG Sun Jan 9 23:40:34 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E284116A4D7 for ; Sun, 9 Jan 2005 23:40:33 +0000 (GMT) Received: from rosebud.otenet.gr (rosebud.otenet.gr [195.170.0.26]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9347743D3F for ; Sun, 9 Jan 2005 23:40:32 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-b154.otenet.gr [212.205.244.162]) j09NeNXV022258 for ; Mon, 10 Jan 2005 01:40:23 +0200 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.13.1/8.13.1) with ESMTP id j09NeMF2083041 for ; Mon, 10 Jan 2005 01:40:22 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.13.1/8.13.1/Submit) id j09NeMD6083040 for freebsd-questions@freebsd.org; Mon, 10 Jan 2005 01:40:22 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Mon, 10 Jan 2005 01:40:21 +0200 From: Giorgos Keramidas To: freebsd-questions@freebsd.org Message-ID: <20050109234021.GB75804@gothmog.gr> References: <14545951.20050110000835@wanadoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14545951.20050110000835@wanadoo.fr> Subject: Re: Copying directory trees only for new files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Jan 2005 23:40:34 -0000 On 2005-01-10 00:08, Anthony Atkielski wrote: > What's the safest and most elegant way to copy an entire directory tree > such that only newer files and directories are actually copied? cpio(1) does that by default (to overwrite files in the destination path that are newer with older copies from the source hierarchy, you have to force overwriting with the -u option). You can use it in `pass through' mode to copy entire hierarchies to another place: % gothmog:/tmp$ rm -fr newstuff % gothmog:/tmp$ find oldstuff | xargs ls -ld % drwxrwxr-x 4 giorgos wheel 512 Jan 10 01:34 oldstuff % drwxrwxr-x 3 giorgos wheel 512 Jan 10 01:34 oldstuff/bar % drwxrwxr-x 2 giorgos wheel 512 Jan 10 01:34 oldstuff/bar/baz % -rw-rw-r-- 1 giorgos wheel 12 Jan 10 01:34 oldstuff/bar/baz/kazaam % drwxrwxr-x 3 giorgos wheel 512 Jan 10 01:34 oldstuff/foo % drwxrwxr-x 2 giorgos wheel 512 Jan 10 01:34 oldstuff/foo/bar % -rw-rw-r-- 1 giorgos wheel 12 Jan 10 01:35 oldstuff/foo/bar/xyz % gothmog:/tmp$ cp -Rp oldstuff newstuff % gothmog:/tmp$ touch oldstuff/bar/baz/kazaam % gothmog:/tmp$ ( cd oldstuff ; find . | cpio -p -dmv /tmp/newstuff ) % /tmp/newstuff/./foo % /tmp/newstuff/./foo/bar % cpio: /tmp/newstuff/./foo/bar/xyz not created: newer or same age version exists % /tmp/newstuff/./bar % /tmp/newstuff/./bar/baz % /tmp/newstuff/./bar/baz/kazaam % 1 block % gothmog:/tmp$ Note that foo/bar/xyz is skipped, since it didn't change, but bar/baz/kazaam is copied because it was touched. - Giorgos