| www.delorie.com/gnu/docs/fileutils/fileutils_38.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
cp: Copy files and directories
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. However, the
`-R', `-a', and `-r' options cause cp to
copy recursively by descending into source directories and copying files
to corresponding destination directories.
By default, cp follows symbolic links only when not copying
recursively. This default can be overridden with the
`--no-dereference' (`-d'), `--dereference'
(`-L'), and `-H' options. If more than one of these
options is specified, the last one silently overrides the others.
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 2.1 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 2. Common options.
cp makes a backup of source when the force
and backup options are given and source and dest are the same
name for an existing, regular file. One useful application of this
combination of options is this tiny Bourne shell script:
#!/bin/sh # Usage: backup FILE... # Create a GNU-style backup of each listed FILE. for i in "$@"; do cp --backup --force "$i" "$i" done |
cp then unlinks it and
tries to open it again. Contrast this behavior with that enabled by
`--link' and `--symbolic-link', whereby the destination file
is never opened but rather is unlinked unconditionally. Also see the
description of `--remove-destination'.
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.
Warning: the meaning of `-P' will change in the future to conform to POSIX. Use `--parents' for the old meaning, and `--no-dereference' for the new.
cp -r to special files like FIFOs and the ones typically
found in the `/dev' directory. In most cases, cp -r
will hang indefinitely trying to read from FIFOs and special files
like `/dev/console', and it will fill up your destination disk
if you use it to copy `/dev/zero'.
Use the `--recursive' (`-R') option instead if you want
to copy special files, preserving their special nature
rather than reading from them to copy their contents.
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:
mkswap command,
since such a file must not have any holes.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |