Go to the first, previous, next, last section, table of contents.
cp
copies files (or, optionally, directories). The copy is
completely independent of the original. You can either copy one file to
another, or copy arbitrarily many files to a destination directory.
Synopsis:
cp [option]... source dest
cp [option]... source... directory
If the last argument names an existing directory, cp
copies each
source file into that directory (retaining the same name).
Otherwise, if only two files are given, it copies the first onto the
second. It is an error if the last argument is not a directory and more
than two non-option arguments are given.
Generally, files are written just as they are read. For exceptions,
see the `--sparse' option below.
By default, cp
does not copy directories (see `-r' below).
cp
generally refuses to copy a file onto itself, with the
following exception: if `--force --backup' is specified with
source and dest identical, and referring to a regular file,
cp
will make a backup file, either regular or numbered, as
specified in the usual ways (see section Backup options). This is useful when
you simply want to make a backup of an existing file before changing it.
The program accepts the following options. Also see section Common options.
- `-a'
-
- `--archive'
-
Preserve as much as possible of the structure and attributes of the
original files in the copy (but do not preserve directory structure).
Equivalent to `-dpR'.
- `-b'
-
- `--backup'
-
Make backups of files that are about to be overwritten or removed.
See section Backup options.
- `-d'
-
- `--no-dereference'
-
Copy symbolic links as symbolic links rather than copying the files that
they point to, and preserve hard links between source files in the
copies.
- `-f'
-
- `--force'
-
Remove existing destination files.
- `-i'
-
- `--interactive'
-
Prompt whether to overwrite existing regular destination files.
- `-l'
-
- `--link'
-
Make hard links instead of copies of non-directories.
- `-p'
-
- `--preserve'
-
Preserve the original files' owner, group, permissions, and timestamps.
- `-P'
-
- `--parents'
-
Form the name of each destination file by appending to the target
directory a slash and the specified name of the source file. The last
argument given to
cp
must be the name of an existing directory.
For example, the command:
cp --parents a/b/c existing_dir
copies the file `a/b/c' to `existing_dir/a/b/c', creating
any missing intermediate directories.
- `-r'
-
Copy directories recursively, copying any non-directories and
non-symbolic links (that is, FIFOs and special files) as if they were
regular files. This means trying to read the data in each source file
and writing it to the destination. Thus, with this option,
cp
may well hang indefinitely reading a FIFO, unless something else happens
to be writing it.
- `-R'
-
- `--recursive'
-
Copy directories recursively, preserving non-directories (see `-r'
just above).
- `--sparse=when'
-
A sparse file contains holes---a sequence of zero bytes that
does not occupy any physical disk blocks; the `read' system call
reads these as zeroes. This can both save considerable disk space and
increase speed, since many binary files contain lots of consecutive zero
bytes. By default,
cp
detects holes in input source files via a crude
heuristic and makes the corresponding output file sparse as well.
The when value can be one of the following:
- `auto'
-
The default behavior: the output file is sparse if the input file is sparse.
- `always'
-
Always make the output file sparse. This is useful when the input
file resides on a filesystem that does not support sparse files (the
most notable example is `efs' filesystems in SGI IRIX 5.3 and
earlier), but the output file is on another type of filesystem.
- `never'
-
Never make the output file sparse. If you find an application for this
option, let us know.
- `-s'
-
- `--symbolic-link'
-
Make symbolic links instead of copies of non-directories. All source
file names must be absolute (starting with `/') unless the
destination files are in the current directory. This option merely
results in an error message on systems that do not support symbolic links.
- `-S suffix'
-
- `--suffix=suffix'
-
Append suffix to each backup file made with `-b'.
See section Backup options.
- `-u'
-
- `--update'
-
Do not copy a nondirectory that has an existing destination with the
same or newer modification time.
- `-v'
-
- `--verbose'
-
Print the name of each file before copying it.
- `-V method'
-
- `--version-control=method'
-
Change the type of backups made with `-b'. The method
argument can be `numbered' (or `t'), `existing' (or
`nil'), or `never' (or `simple'). See section Backup options.
- `-x'
-
- `--one-file-system'
-
Skip subdirectories that are on different filesystems from the one that
the copy started on.
Go to the first, previous, next, last section, table of contents.