xref: /netbsd-src/bin/cp/cp.1 (revision 6326f9f26c07995979f554307fda3248502ba8ef)
1*6326f9f2Sgutteridge.\"	$NetBSD: cp.1,v 1.46 2018/12/23 01:29:23 gutteridge Exp $
249f0ad86Scgd.\"
3051219a6Smycroft.\" Copyright (c) 1989, 1990, 1993, 1994
4051219a6Smycroft.\"	The Regents of the University of California.  All rights reserved.
561f28255Scgd.\"
661f28255Scgd.\" This code is derived from software contributed to Berkeley by
761f28255Scgd.\" the Institute of Electrical and Electronics Engineers, Inc.
861f28255Scgd.\"
961f28255Scgd.\" Redistribution and use in source and binary forms, with or without
1061f28255Scgd.\" modification, are permitted provided that the following conditions
1161f28255Scgd.\" are met:
1261f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1361f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1461f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1561f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1661f28255Scgd.\"    documentation and/or other materials provided with the distribution.
17b5b29542Sagc.\" 3. Neither the name of the University nor the names of its contributors
1861f28255Scgd.\"    may be used to endorse or promote products derived from this software
1961f28255Scgd.\"    without specific prior written permission.
2061f28255Scgd.\"
2161f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2261f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2361f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2461f28255Scgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2561f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2661f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2761f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2861f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2961f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3061f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3161f28255Scgd.\" SUCH DAMAGE.
3261f28255Scgd.\"
3349f0ad86Scgd.\"	@(#)cp.1	8.3 (Berkeley) 4/18/94
34346aa5ddScgd.\"
35*6326f9f2Sgutteridge.Dd December 22, 2018
3661f28255Scgd.Dt CP 1
37f1247650Sgarbled.Os
3861f28255Scgd.Sh NAME
3961f28255Scgd.Nm cp
4061f28255Scgd.Nd copy files
4161f28255Scgd.Sh SYNOPSIS
42df49b6ccSlukem.Nm
43051219a6Smycroft.Oo
44051219a6Smycroft.Fl R
45e2c77845Shira.Op Fl H | Fl L | Fl P
46051219a6Smycroft.Oc
478a99d7cfSwsanchez.Op Fl f | i
48d8781269Sdarcy.Op Fl alNpv
4961f28255Scgd.Ar source_file target_file
508a99d7cfSwsanchez.Nm cp
51051219a6Smycroft.Oo
52051219a6Smycroft.Fl R
53e2c77845Shira.Op Fl H | Fl L | Fl P
54051219a6Smycroft.Oc
558a99d7cfSwsanchez.Op Fl f | i
56d8781269Sdarcy.Op Fl alNpv
5761f28255Scgd.Ar source_file ... target_directory
5861f28255Scgd.Sh DESCRIPTION
5961f28255ScgdIn the first synopsis form, the
60df49b6ccSlukem.Nm
6161f28255Scgdutility copies the contents of the
6261f28255Scgd.Ar source_file
6361f28255Scgdto the
6461f28255Scgd.Ar target_file .
6561f28255ScgdIn the second synopsis form,
6661f28255Scgdthe contents of each named
6761f28255Scgd.Ar source_file
6861f28255Scgdis copied to the destination
6961f28255Scgd.Ar target_directory .
7061f28255ScgdThe names of the files themselves are not changed.
7161f28255ScgdIf
72df49b6ccSlukem.Nm
7361f28255Scgddetects an attempt to copy a file to itself, the copy will fail.
7461f28255Scgd.Pp
7561f28255ScgdThe following options are available:
7661f28255Scgd.Bl -tag -width flag
771e774072Swiz.It Fl a
781e774072SwizArchive mode.
791e774072SwizSame as
801e774072Swiz.Fl RpP .
81d8b6049eSwiz.It Fl f
82d8b6049eSwizFor each existing destination pathname, attempt to overwrite it.
83d8b6049eSwizIf permissions do not allow copy to succeed, remove it and create a new
84d8b6049eSwizfile, without prompting for confirmation.
85d8b6049eSwiz(The
86d8b6049eSwiz.Fl i
87d8b6049eSwizoption is ignored if the
88d8b6049eSwiz.Fl f
89d8b6049eSwizoption is specified.)
90051219a6Smycroft.It Fl H
91051219a6SmycroftIf the
92051219a6Smycroft.Fl R
93051219a6Smycroftoption is specified, symbolic links on the command line are followed.
94051219a6Smycroft(Symbolic links encountered in the tree traversal are not followed.)
95d8b6049eSwiz.It Fl i
96d8b6049eSwizCauses
97d8b6049eSwiz.Nm
98d8b6049eSwizto write a prompt to the standard error output before copying a file
99d8b6049eSwizthat would overwrite an existing file.
100d8b6049eSwizIf the response from the standard input begins with the character
101d8b6049eSwiz.Sq Li y ,
102d8b6049eSwizthe file copy is attempted.
103051219a6Smycroft.It Fl L
104051219a6SmycroftIf the
105051219a6Smycroft.Fl R
106051219a6Smycroftoption is specified, all symbolic links are followed.
107d8781269Sdarcy.It Fl l
108d8781269SdarcyCreate hard links to regular files in a hierarchy instead of copying.
10976ed05e8Selad.It Fl N
11076ed05e8SeladWhen used with
11176ed05e8Selad.Fl p ,
11276ed05e8Seladdon't copy file flags.
113051219a6Smycroft.It Fl P
114471c8a8eSjschaumaNo symbolic links are followed.
1151d41baa0SchristosThis is the default.
11661f28255Scgd.It Fl p
11761f28255ScgdCauses
118df49b6ccSlukem.Nm
11961f28255Scgdto preserve in the copy as many of the modification time, access time,
120a9ed0e98Smanufile flags, file mode, user ID, group ID, and extended attributes,
121a9ed0e98Smanuas allowed by permissions.
12261f28255Scgd.Pp
123*6326f9f2SgutteridgeIf the user ID and group ID cannot be preserved due to insufficient
124*6326f9f2Sgutteridgepermissions, no error message is displayed and the exit value is not
125*6326f9f2Sgutteridgealtered.
12661f28255Scgd.Pp
12761f28255ScgdIf the source file has its set user ID bit on and the user ID cannot
12861f28255Scgdbe preserved, the set user ID bit is not preserved
12961f28255Scgdin the copy's permissions.
13061f28255ScgdIf the source file has its set group ID bit on and the group ID cannot
13161f28255Scgdbe preserved, the set group ID bit is not preserved
13261f28255Scgdin the copy's permissions.
133051219a6SmycroftIf the source file has both its set user ID and set group ID bits on,
134051219a6Smycroftand either the user ID or group ID cannot be preserved, neither
13561f28255Scgdthe set user ID or set group ID bits are preserved in the copy's
13661f28255Scgdpermissions.
137a9ed0e98Smanu.Pp
1387f03f2caSdhollandExtended attributes from all accessible namespaces are copied;
1397f03f2caSdhollandothers are ignored.
1407f03f2caSdhollandIf an error occurs during this copy, a message is displayed and
1417f03f2caSdholland.Nm
1427f03f2caSdhollandskips the other extended attributes for that file.
143d8b6049eSwiz.It Fl R
144d8b6049eSwizIf
145d8b6049eSwiz.Ar source_file
146d8b6049eSwizdesignates a directory,
147d8b6049eSwiz.Nm
148d8b6049eSwizcopies the directory and the entire subtree connected at that point.
149d8b6049eSwizThis option also causes symbolic links to be copied, rather than
15095f605c2Smbalmerfollowed, and for
151d8b6049eSwiz.Nm
152d8b6049eSwizto create special files rather than copying them as normal files.
153d8b6049eSwizCreated directories have the same mode as the corresponding source
154471c8a8eSjschaumadirectory, unmodified by the process's umask.
15543a44d85Swiz.Pp
15643a44d85SwizNote that
15743a44d85Swiz.Nm
15843a44d85Swizcopies hard linked files as separate files.
15943a44d85SwizIf you need to preserve hard links, consider using a utility like
16043a44d85Swiz.Xr pax 1
16143a44d85Swizinstead.
1624e81454aSjrf.It Fl v
16343a44d85SwizCauses
1644e81454aSjrf.Nm
1654e81454aSjrfto be verbose, showing files as they are copied.
16661f28255Scgd.El
16761f28255Scgd.Pp
16861f28255ScgdFor each destination file that already exists, its contents are
16961f28255Scgdoverwritten if permissions allow, but its mode, user ID, and group
17061f28255ScgdID are unchanged.
17161f28255Scgd.Pp
172051219a6SmycroftIn the second synopsis form,
173051219a6Smycroft.Ar target_directory
174051219a6Smycroftmust exist unless there is only one named
175051219a6Smycroft.Ar source_file
176051219a6Smycroftwhich is a directory and the
177051219a6Smycroft.Fl R
178051219a6Smycroftflag is specified.
179051219a6Smycroft.Pp
18061f28255ScgdIf the destination file does not exist, the mode of the source file is
18161f28255Scgdused as modified by the file mode creation mask
182d8b6049eSwiz.Ic ( umask ,
18361f28255Scgdsee
18461f28255Scgd.Xr csh 1 ) .
18561f28255ScgdIf the source file has its set user ID bit on, that bit is removed
18661f28255Scgdunless both the source file and the destination file are owned by the
18761f28255Scgdsame user.
18861f28255ScgdIf the source file has its set group ID bit on, that bit is removed
18961f28255Scgdunless both the source file and the destination file are in the same
19061f28255Scgdgroup and the user is a member of that group.
19161f28255ScgdIf both the set user ID and set group ID bits are set, all of the above
19261f28255Scgdconditions must be fulfilled or both bits are removed.
19361f28255Scgd.Pp
19461f28255ScgdAppropriate permissions are required for file creation or overwriting.
19561f28255Scgd.Pp
196051219a6SmycroftSymbolic links are always followed unless the
19761f28255Scgd.Fl R
198051219a6Smycroftflag is set, in which case symbolic links are not followed, by default.
199051219a6SmycroftThe
200051219a6Smycroft.Fl H
201051219a6Smycroftor
202051219a6Smycroft.Fl L
203051219a6Smycroftflags (in conjunction with the
204051219a6Smycroft.Fl R
205471c8a8eSjschaumaflag), as well as the
206d8c803bcSjschauma.Fl P
207471c8a8eSjschaumaflag cause symbolic links to be followed as described above.
208471c8a8eSjschaumaThe
209471c8a8eSjschauma.Fl H
210471c8a8eSjschaumaand
211471c8a8eSjschauma.Fl L
212051219a6Smycroftoptions are ignored unless the
213051219a6Smycroft.Fl R
214051219a6Smycroftoption is specified.
215051219a6SmycroftIn addition, these options override each other and the
216051219a6Smycroftcommand's actions are determined by the last one specified.
21781b1fb1dSapbThe default is as if the
21881b1fb1dSapb.Fl P
21981b1fb1dSapboption had been specified.
2202caf6aacSkleink.Sh EXIT STATUS
221d8b6049eSwiz.Ex -std cp
222051219a6Smycroft.Sh COMPATIBILITY
223051219a6SmycroftHistoric versions of the
224df49b6ccSlukem.Nm
225051219a6Smycroftutility had a
226051219a6Smycroft.Fl r
227051219a6Smycroftoption.
228051219a6SmycroftThis implementation supports that option, however, its use is strongly
229dfb9651eSwizdiscouraged, as it does not correctly copy special files, symbolic links,
230dfb9651eSwizor FIFOs.
23161f28255Scgd.Sh SEE ALSO
23261f28255Scgd.Xr mv 1 ,
23343a44d85Swiz.Xr pax 1 ,
23461f28255Scgd.Xr rcp 1 ,
235051219a6Smycroft.Xr umask 2 ,
236051219a6Smycroft.Xr fts 3 ,
237051219a6Smycroft.Xr symlink 7
2381c13dcfdSjtc.Sh STANDARDS
23961f28255ScgdThe
240df49b6ccSlukem.Nm
24123e6aab1Sjtcutility is expected to be
24261f28255Scgd.St -p1003.2
24361f28255Scgdcompatible.
244220d843fSyamt.Pp
2451d41baa0SchristosThe
2461d41baa0Schristos.Fl a
247daf77513Swizand
248daf77513Swiz.Fl l
249daf77513Swizflags are non-standard extensions.
250daf77513SwizThey are intended to be compatible with the same options which
251b259bc7dSwizother implementations, namely GNU coreutils and
252b259bc7dSwiz.Fx ,
253220d843fSyamtof this utility have.
2544e81454aSjrf.Pp
255c8ae14b0SkleinkThe
256c8ae14b0Skleink.Fl v
257c8ae14b0Skleinkoption is an extension to
258c8ae14b0Skleink.St -p1003.2 .
25904e68223Ssevan.Sh HISTORY
26004e68223SsevanA
26104e68223Ssevan.Nm
26204e68223Ssevanutility appeared in
26304e68223Ssevan.At v1 .
264