.TH cpdir "" "" Command
.PC "Copy directory hierarchy"
\fBcpdir [\fIoption ... \fR] \fIdir1 dir2\fR
.PP
.HS
.SH Options:
.IC \fB\-a\fR
Verbose file by file account on one line
.IC \fB\-d\fR
Preserve last-modified date
.IC \fB\-e\fR
Recover from errors and continue
.IC \fB\-r[\fIn\fB]\fI
Recur \fIn\fR levels only (default, one)
.IC \fB\-s\fIname\fR
Suppress copy of \fIname\fR,
which is relative to \fIdir1\fR
.IC \fB\-t\fR
Test and report errors \(em do not change anything
.IC \fB\-u\fR
Update regular files if more recent
.IC \fB\-v\fR
Verbose file by file account
.HE
.B cpdir
copies source directory hierarchy
.I dir1
to target hierarchy
.I dir2,
which is created if necessary.
Either hierarchy may straddle device boundaries.
.PP
.B cpdir
preserves as much as possible of the source structure.
Files under
.I dir1
go to identically named files under
.I dir2.
Links between source files are preserved as links between
corresponding target files.
Preserved source file attributes include mode, subject to the user's
file creation mask.
If the user is not the superuser,
.B cpdir
cannot preserve the owner, group, and sticky bits in the mode,
and the invoking user owns all new files;
under the superuser it preserves these as well.
In addition, the superuser may ``copy'' special nodes and pipe nodes;
.B cpdir
copies only the facility, not the contents.
It also preserves real major and minor device numbers of special nodes.
.PP
If the target file corresponding to a source file exists and is not a directory,
.B cpdir
unlinks it before copying.
This differs from the action of
.BR cp .
.PP
.B cpdir
recognizes the following options:
.RS
.IP \fB\-a\fR
Give a verbose account on one line of the files copied.
.IP \fB\-d\fR
Preserve the last-modified date instead of using the present date.
.IP \fB\-e\fR
Print error message and continue execution
after an error.
The default action is to
exit on any error.
.IP "\fB\-r [\fIn\^\fB]\fR"
Descend no more than
.I n
levels in the source hierarchy.
Contents of
.I dir1
are at level 1.
If missing,
.I n
defaults to 1.
.IP "\fB\-s \fIname\fR"
Suppress the copy of file
.IR name ,
which
should be the pathname of the file relative to
.I dir1.
.IP \fB\-t\fR
Test only, make no changes.
With this option,
.B cpdir
prints a report of all errors
.RB ( \-e
is implied),
all unlinked target files, and other useful information, including
a summary of all external links into the target hierarchy
that would have been
broken had the unlinking actions been executed.
.IP \fB\-u\fR
Update regular files.
Copy the source only if it was created or altered
more recently than the target file,
or if the target does not exist.
.IP \fB\-v\fR
Print a verbose account of its activities.
.B cp
prints a file-by-file account of its actions,
in addition to the information listed under
.B \-t.
.RE
.SH "See Also"
.Xr "commands," commands
.Xr "cp," cp
.Xr "link()," link()
.Xr "umask()," umask()
.Xr "unlink()" unlink()
