[net.sources] cpdir shell script & man page for 4.2 BSD

RSanders@DENVER.ARPA (04/23/85)

Yes, this is a trivial hack, but somebody had to do it.  Cut at the
dotted lines.  Works for us on VAX/4.2 BSD - others, beware.

-- Rex
............................................................................
.TH CPDIR 1 LOCAL "USGS Pacific Marine Geology"
.SH NAME
cpdir - copy directory (and subdirectories)
.SH SYNOPSIS
.B cpdir
dir1 dir2
.SH DESCRIPTION
.I Dir1
is copied into
.IR dir2 ,
complete with files and subdirectories.
.I Dir2
is created, if necessary.
.PP
Modify and access times of files are preserved;
modify and access times of
.I dir2
(if created) and any subdirectories are not preserved.
Ownership and access modes are preserved for all files and directories,
except for
.I dir2
if it is created.
.SH "SEE ALSO"
cp(1), mkdir(1), mv(1), tar(1)
.SH AUTHOR
Rex Sanders, U.S. Geological Survey, Pacific Marine Geology
...............................................................................
#! /bin/sh
# cpdir - copies an existing directory (and subtree) to a new dir
#   Rex Sanders, USGS Pacific Marine Geology
if [ $# -ne 2 ]
then
  echo "Usage:  cpdir olddir newdir"
  exit 1
fi
owd=`pwd`
if test -d $2
then
  cd $1 &&  tar cf - . | ( cd $owd; cd $2; tar xf - )
else
  mkdir $2 &&  cd $1 &&  tar cf - . | ( cd $owd; cd $2; tar xf - )
fi

rzdz@fluke.UUCP (Rick Chinn) (05/01/85)

> Yes, this is a trivial hack, but somebody had to do it.  Cut at the
> dotted lines.  Works for us on VAX/4.2 BSD - others, beware.
> 
> -- Rex
> ............................................................................
> .TH CPDIR 1 LOCAL "USGS Pacific Marine Geology"
> .SH NAME
> cpdir - copy directory (and subdirectories)
 ...

Pardon me, but doesn't the -r option to cp do the same thing?

...truncated portion of cp man page:

     cp [ -i ] [ -r ] file1 file2

     cp [ -i ] [ -r ] file ... directory

DESCRIPTION

     If the -r option is specified and any of the source files
     are directories, cp copies each subtree rooted at that name;
     in this case the destination must be a directory.

--------------
works good for me...

I tried direct e-mail, but the mailer bounced it back... must have been
gatewayed from arpanet. oh-well...

Rick Chinn
John Fluke Mfg. Co MS 232E
PO Box C9090 Everett WA 98206

{ihnp4!uw-beaver, ucbvax!lbl-csam, microsoft, allegra, ssc-vax}!fluke!rzdz
(206) 356-5232

rlr@avsdT.UUCP (Rhode Roberts) (05/16/85)

> > Yes, this is a trivial hack, but somebody had to do it.  Cut at the
> > dotted lines.  Works for us on VAX/4.2 BSD - others, beware.
> > 
> > -- Rex
> > ............................................................................
> > .TH CPDIR 1 LOCAL "USGS Pacific Marine Geology"
> > .SH NAME
> > cpdir - copy directory (and subdirectories)
>  ...
> 
> Pardon me, but doesn't the -r option to cp do the same thing?
> 
> ...truncated portion of cp man page:
> 
>      cp [ -i ] [ -r ] file1 file2
> 
>      cp [ -i ] [ -r ] file ... directory
> 
> DESCRIPTION
> 
>      If the -r option is specified and any of the source files
>      are directories, cp copies each subtree rooted at that name;
>      in this case the destination must be a directory.
> 
> --------------
> works good for me...
> 
> I tried direct e-mail, but the mailer bounced it back... must have been
> gatewayed from arpanet. oh-well...
> 
> Rick Chinn
> John Fluke Mfg. Co MS 232E
> PO Box C9090 Everett WA 98206
> 
> {ihnp4!uw-beaver, ucbvax!lbl-csam, microsoft, allegra, ssc-vax}!fluke!rzdz
> (206) 356-5232

*** REPLACE THIS LINE WITH YOUR MESSAGE ***

some people don't like to do things the easy way as in "cp -r".
so here is ( right out of the maual ) the tar version.
#
# Phony tree cp
#
#
if( $#argv != 2 ) then
	echo Incorrect Usage
	echo treecp path/dir_name dir_name
	echo \(path/dir is the directory to be copied\)
	echo \(dir_name is the name for the new directory\)
	exit ( 0 )
endif

set noglob
set target_path=`pwd`
set target=`echo $target_path/${2}`

mkdir $target
cd ${1} ; tar cf - . | ( cd $target ; tar xf - . )