9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] dcp - a deep copy script, better than dircp
@ 2009-07-19 16:24 Ethan Grammatikidis
  2009-07-19 18:05 ` erik quanstrom
  2009-07-20  9:32 ` cej
  0 siblings, 2 replies; 24+ messages in thread
From: Ethan Grammatikidis @ 2009-07-19 16:24 UTC (permalink / raw)
  To: 9fans

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?



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2014-04-17 12:55 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-19 16:24 [9fans] dcp - a deep copy script, better than dircp Ethan Grammatikidis
2009-07-19 18:05 ` erik quanstrom
2009-07-19 18:16   ` Richard Miller
2009-07-19 18:34     ` Francisco J Ballesteros
2009-07-20  1:32   ` Ethan Grammatikidis
2009-07-20  9:55     ` Charles Forsyth
2009-07-20 11:36       ` Ethan Grammatikidis
2009-07-20 11:50         ` erik quanstrom
2009-07-20 13:25           ` Ethan Grammatikidis
2009-07-20 14:00             ` Steve Simon
2009-07-20 15:02               ` Ethan Grammatikidis
2009-07-20 15:13                 ` erik quanstrom
2009-07-20 15:19                 ` Dan Cross
2009-07-20 18:30                   ` Ethan Grammatikidis
2009-07-20 22:25                     ` Jason Catena
2009-07-20 22:41                       ` erik quanstrom
2009-07-20 22:51                         ` Jack Johnson
2009-07-20 22:56                           ` erik quanstrom
2009-07-21  0:31                             ` Dan Cross
2009-07-23  2:10       ` Federico G. Benavento
2009-07-20  9:32 ` cej
2009-07-20 11:04   ` Ethan Grammatikidis
2014-04-17 12:53   ` arisawa
2014-04-17 12:55     ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).