cpdir shell script & man page for 4.2 BSD

RSanders at DENVER.ARPA RSanders at DENVER.ARPA
Tue Apr 23 10:32:29 AEST 1985


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



More information about the Comp.sources.unix mailing list