Cp: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 11: Line 11:
cp <source-file> <source-file> ... <target-dir>
cp <source-file> <source-file> ... <target-dir>
</syntaxhighlight>
</syntaxhighlight>
To perform a recursive copy that preserves file attributes, use [[#-a.7C--archive|--archive]].


=Options=
=Options=
Line 16: Line 18:
==-R==
==-R==


If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory are copied rather than the directory
If <source-file> designates a directory, cp copies the directory and the entire subtree connected at that point. If <source-file> ends in a /, the contents of the directory are copied rather than the directory itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files.  Created directories have the same mode as the corresponding source directory, unmodified by the process' umask.
          itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files.  Created directories have the same mode as
          the corresponding source directory, unmodified by the process' umask.


          In -R mode, cp will continue copying even if errors are detected.
In -R mode, cp will continue copying even if errors are detected.


          Note that cp copies hard-linked files as separate files.  If you need to preserve hard links, consider using tar(1), cpio(1), or pax(1) instead.
Note that cp copies hard-linked files as separate files.  If you need to preserve hard links, consider using tar or cpio.


==-r==
==-r==


Historic option for copying recursively. It is deprecated, use [[#-R|-R]] instead.
On Mac, historic option for copying recursively. It is deprecated, use [[#-R|-R]] instead.
 
==-a|--archive==
 
Same as -[[#-d|d]][[#-R|R]] [[#--preserve|--preserve]]=all
 
==-d==
 
Same as [[#-P.7C--no-dereference|--no-dereference]] [[#--preserve|--preserve]]=links
 
==--preserve==
<syntaxhighlight lang='bash'>
--preserve[=ATTR_LIST]
</syntaxhighlight>
 
where ATTR_LIST can be:
* mode (included in default behavior if --preserve is invoked without any arguments)
* ownership (included in default behavior if --preserve is invoked without any arguments)
* timestamps (included in default behavior if --preserve is invoked without any arguments)
* context
* links
* xattr
* all
 
==-P|--no-dereference==
Never follow symbolic links in <source-dir>.

Latest revision as of 02:36, 27 December 2020

Internal

Overview

cp <source-file> <target-file>
cp <source-file> <source-file> ... <target-dir>

To perform a recursive copy that preserves file attributes, use --archive.

Options

-R

If <source-file> designates a directory, cp copies the directory and the entire subtree connected at that point. If <source-file> ends in a /, the contents of the directory are copied rather than the directory itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask.

In -R mode, cp will continue copying even if errors are detected.

Note that cp copies hard-linked files as separate files. If you need to preserve hard links, consider using tar or cpio.

-r

On Mac, historic option for copying recursively. It is deprecated, use -R instead.

-a|--archive

Same as -dR --preserve=all

-d

Same as --no-dereference --preserve=links

--preserve

--preserve[=ATTR_LIST]

where ATTR_LIST can be:

  • mode (included in default behavior if --preserve is invoked without any arguments)
  • ownership (included in default behavior if --preserve is invoked without any arguments)
  • timestamps (included in default behavior if --preserve is invoked without any arguments)
  • context
  • links
  • xattr
  • all

-P|--no-dereference

Never follow symbolic links in <source-dir>.