Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 01 Oct 2002 21:14:06 +0200
From:      Marc Perisa <perisa@porsche.de>
To:        Peter Leftwich <Hostmaster@Video2Video.Com>
Cc:        FreeBSD LIST <FreeBSD-Questions@FreeBSD.Org>
Subject:   Re: Copying directories contents
Message-ID:  <3D99F3FE.4070801@porsche.de>
References:  <20021001140103.G2271-100000@earl-grey.cloud9.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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




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