theshell.ch/site/pages/fs/cp.html

53 lines
2.1 KiB
HTML
Raw Normal View History

---
layout: page
category-page: fs
category-title: FileSystem
tags: directory list copy cp
author: Mattia Hijman
title: cp
previous-page: pages/fs/cd.html
previous-next: pages/fs/du.html
---
The <code>cp</code> command copies the contents of one or more files or directories to a
target file or directory.<br>
<pre>
cp [source1] [source2] [source3] ... [target]
</pre>
<h3>Flags</h3>
<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>