2018-11-19 12:47:44 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: fs
|
|
|
|
category-title: FileSystem
|
|
|
|
tags: directory list copy cp
|
|
|
|
author: Mattia Hijman
|
2018-11-19 12:52:02 +00:00
|
|
|
title: cp
|
2018-11-19 14:57:49 +00:00
|
|
|
previous-page: pages/fs/cd.html
|
|
|
|
previous-next: pages/fs/du.html
|
2018-11-19 12:47:44 +00:00
|
|
|
---
|
|
|
|
|
2018-11-19 14:57:49 +00:00
|
|
|
The <code>cp</code> command copies the contents of one or more files or directories to a
|
|
|
|
target file or directory.<br>
|
2018-11-19 12:47:44 +00:00
|
|
|
|
2018-11-19 14:57:49 +00:00
|
|
|
<pre>
|
|
|
|
cp [source1] [source2] [source3] ... [target]
|
|
|
|
</pre>
|
2018-11-19 12:47:44 +00:00
|
|
|
|
|
|
|
|
2018-11-19 14:57:49 +00:00
|
|
|
<h3>Flags</h3>
|
2018-11-19 12:47:44 +00:00
|
|
|
|
2018-11-19 14:57:49 +00:00
|
|
|
<ul>
|
|
|
|
<li><b>-a</b>: Same as -pPR options. Preserves structure and attributes of files
|
|
|
|
but not directory structure.
|
|
|
|
</li>
|
|
|
|
<li><b>-f</b>: If the destination file cannot be opened, remove it and create a new file,
|
|
|
|
without prompting for confirmation regardless of its permissions.
|
|
|
|
The target file is not unlinked before the copy,
|
|
|
|
so any existing access rights will be retained.
|
|
|
|
</li>
|
|
|
|
<li><b>-H</b>: If -R is specified, symbolic links on the command line are followed.</li>
|
|
|
|
<li><b>-i</b>: Cause cp to write a prompt to the standard error output before
|
|
|
|
copying a file that would overwrite an existing file. If the
|
|
|
|
response from the standard input begins with the character <i>y</i> or
|
|
|
|
<i>Y</i>, the file copy is attempted.
|
|
|
|
</li>
|
|
|
|
<li><b>-L</b>: If the -R option is specified, all symbolic links are followed.</li>
|
|
|
|
<li><b>-n</b>: Do not overwrite an existing file.</li>
|
|
|
|
<li><b>-P</b>: If the -R option is specified, no symbolic links are followed.</li>
|
|
|
|
<li><b>-p</b>: Cause cp to preserve the following attributes of each source file
|
|
|
|
in the copy.
|
|
|
|
</li>
|
|
|
|
<li><b>-R</b>: 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 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.
|
|
|
|
</li>
|
|
|
|
<li><b>-v</b>: Cause cp to be verbose, showing files as they are copied.</li>
|
|
|
|
<li><b>-X</b>: Do not copy Extended Attributes (EAs) or resource forks.</li>
|
|
|
|
</ul>
|