From owner-freebsd-questions Tue Oct 1 12: 7: 1 2002 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 0898A37B401 for ; Tue, 1 Oct 2002 12:07:00 -0700 (PDT) Received: from gate21.fw.porsche.de (gate23.fw.porsche.de [193.174.9.99]) by mx1.FreeBSD.org (Postfix) with SMTP id A133843E6A for ; Tue, 1 Oct 2002 12:06:58 -0700 (PDT) (envelope-from perisa@porsche.de) Received: (qmail 25798 invoked from network); 1 Oct 2002 19:14:10 -0000 Received: from unknown (HELO wuxin011.ibd.porsche.de) (141.36.65.1) by 193.197.149.150 with SMTP; 1 Oct 2002 19:14:10 -0000 Received: (qmail 7937 invoked from network); 1 Oct 2002 19:06:55 -0000 Received: from beastie.ibd.porsche.de (HELO porsche.de) (141.36.3.29) by smtp4cli.ibd.porsche.de with SMTP; 1 Oct 2002 19:06:54 -0000 Message-ID: <3D99F3FE.4070801@porsche.de> Date: Tue, 01 Oct 2002 21:14:06 +0200 From: Marc Perisa User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.0.0) Gecko/20020709 X-Accept-Language: en, de-de, es-es MIME-Version: 1.0 To: Peter Leftwich Cc: FreeBSD LIST Subject: Re: Copying directories contents References: <20021001140103.G2271-100000@earl-grey.cloud9.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Peter Leftwich wrote: > > I have often run into a similar situation. There doesn't seem to be a > command line or GUI file explorer you can use to "stitch together" source > directories and subdirectories into the target directory. For example, if > you have differing files but in the same exact folder tree structure, is > there a command to weave (mv) the files in? This would be a scheme that > favors only files and that runs a "test" of basically saying "is the > directory there already? yes, then mv this file into it, no, then create it > and move this file into it..." but on a wider scale. > # NOT TESTED! # little script, should work in ksh (and zsh && bash) SOURCE=/your/source/dir TARGET=/your/target/dir for i in `cd ${SOURCE}; find . -type d`; do if [[ -d $TARGET/$i ]] ; then mv $SOURCE/$i/* $TARGET/$i/ ; else mv $SOURCE/$i $TARGET/ ; fi ; done Before the mv you can actually test the files (or subdirs) for size, mtime, atime, .... But be careful as stated in the mv(1) man page: As the rename(2) call does not work across file systems, mv uses cp(1) and rm(1) to accomplish the move. The effect is equivalent to: rm -f destination_path && \ cp -pRP source_file destination && \ rm -rf source_file Perhaps you should read some tutorials about shell programming - it can come in really handy. Hope that helps Marc To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message