From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sun, 19 Jul 2009 17:24:15 +0100 From: Ethan Grammatikidis To: 9fans@9fans.net Message-Id: <20090719172415.b7279d56.eekee57@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [9fans] dcp - a deep copy script, better than dircp Topicbox-Message-UUID: 27698c82-ead5-11e9-9d60-3106f5b1d025 I was never satisfied with dircp. It's practice of copying the contents of one directory into another seemed limiting at best, obstructive at worst. The recursive copy options of Gnu cp seemed much more elegant(!), preserving the usual option syntax of cp and merely extending it slightly to include directories. It's no minor issue for me, I move directories around enough that the lack of a convenient facility to do so would prevent regular usage of any OS. Perhaps a _move_ as such would challenge the internal structure of Plan 9 but a convenient deep copy will suffice, not automating removal after copy just in case it goes wrong. And so I wrote an rc script. It takes an unlimited number of source files or directories and copies them all into a destination directory. (Note: unlike dircp it doesn't copy the _contents_ of the sources, it copies the sources themselves.) It differs from Gnu cp in that it will fail if the destination does not exist or is not a directory. In this it is more consistent, it will always (attempt to) copy src* into dest, there is no ambiguity in the case of 2 arguments. NOTE: The script as a whole has not been fully tested. However the variable assignments which do all the clever stuff have been very carefully tested. Posted on the web at http://eekee.org.uk/plan9/scripts/dcp and pasted here for discussion. #!/bin/rc # dcp src* dest # Deep copy all items _src*_ into directory _dest_. # Preserves permissions and ownership as far as # possible, behaving similarly to Gnu cp -a. # # This differs from dircp which deep-copies # the _contents_ of one directory into another. if ( test $#* -lt 2 ) { echo 'usage: dcp from{file|dir} ... todir' exit usage } nsrc = `{ echo $#* 1 - p q | dc } sources = $*(1-$nsrc) # would you believe that line preserves spaces in # arguments? rc ist gut! dest = $*($#*) tar -c $sources | @{builtin cd $dest && tar -xT} # Note: dircp points its tar processes at the files # /def/fd/1 and /dev/fd/0. Anyone know why?