cp - copy files and directories

Overview

cp [ options ] file path
cp [ options ] file ... directory

POSIX options: [-fipRr]

GNU parameters (shortest form): [-abdfilprsuvxPR] [-S SUFFIX ] [-V {Numbered, existing, Simple}] [- sparse = the WHEN ] [--help] [--version] [-]

description

cp copy file (or directory). You can use this command to copy a file to a specified destination, or any number of files copied to a directory object directory.

If the last command parameter is the name of an existing directory, cp will each source file is copied to that directory (to maintain the original file name). If the given parameter file name only two. It copies the file to the previous one on a file. If the last argument is not a file name, directory name, and given more than two non-option argument is wrong.

 

(Thus: if / b already exists, 'cp -r / a / b' is copied / a to / b becomes / b / a and copy / a / x to / b becomes / b / a / x. but if / b does not exist beforehand, it will / a copy of / b and replication / a / x to / b becomes / b / a / x, but if / b does not exist beforehand, it will / a copy It is a / b and the / a / x replicated as / b / x.)

Files and / or directories modes mode and original file that is created is the same, then the user to modify the value of umask (unless the -p option), (but when recursively copy directory, the new directory will temporarily get their final mode Ored, along with S_IRWXU (0700), so that the process can read, write, look for these new directory.

Copy the file to its own it does nothing at all (except an error message may be generated outside) when copying to a different existing file, the system calls the function `open. (Path, O_WRONLY | O_TRUNC) ' Open the destination file. when copying to a new file, the system calls the function `open (path, O_WRONLY | O_CREAT , mode) ' creates the file if this operation fails, the file exists, and the -f option,. cp tries to delete the existing file, if deleted successfully treat it as a new file handling.

POSIX options

POSIX identifies four options and a half:

-f
If necessary, remove the existing destination file. (As previously described.)
-i
Prompted to overwrite the existing ordinary object files. (Displayed in the standard error on the question, the answer is read from the standard input. Only a clear confirmation before copying files.)
-p
Retain the original file's owner, group, permissions (including the setuid and setgid bits), last modified time, and last access time. Error If you make a copy of the owner or group information, the setuid and setgid bits are cleared. (Or else the source file and a copy of the last access time is obviously different, because the copy operation is access to source files.)
-R
Recursive copy directories, if the object is not a regular file or directory then accordingly processed correctly (and therefore, a FIFO or special file after copying is still a FIFO type or the appropriate special file.)
-r
Recursive copy directories, if the object is not a regular file or directory is not declared then do some processing. (We therefore allow and encourage to do with the -r option a synonym for -R. However, those stupid features, like those in the GNU version of cp appear (see below) can also be used.)

GNU details

In general, reading and writing files are the same. Exceptions see below --sparse options.

By default, `cp 'does not copy the directory (see below -r option described).

cp usually not copy the file to itself, with the following exceptions: if the parameter --force --backup with source files are given together, and with the purpose of the file and points to an ordinary file, cp will generate a backup file is not an ordinary numbered, just as the usual method that statement. you just want the existing files are backed up, but do not want to modify it when useful.

GNU Options

-a, --archive
When you copy, as far as possible to maintain the structure and properties of the file. (But do not keep the directory structure) is equivalent to -dpR .
-d, --no-dereference
Copy symbolic links as symbolic links rather than copying the file it points to, and protection of a hard link between the copy of the Zhongyuan file.
-f, --force
Delete the target file exists. (Compared: the original translation missing section below)
-i, --interactive
Whether or not to overwrite an existing file as a reminder.
-l, --link
Make hard links instead of copies of non-directories.
-p, --preserve
Keep the original file's owner, group, permissions, and schedule attributes.
-P, --parents
A slash and the specified source file name constitute the destination file. Finally gave cp parameter must be the name of an existing directory. For example, the following command:
cp --parents a/b/c existing_dir

Copy the file `a / b / c 'to texisting_dir (existing directory) / 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 look the same. This means that attempts to read out the data of each source file, and write it on the destination. therefore, with this option, cp 'may be completely terminated, when indefinitely reading a FIFO or / dev / tty, (which is a drawback. it means that if you do not know this tree (directory) What has to be copied, you have to avoid -r and use -R to open an unknown device file, say a scanner, there will be an unknown effect occurs on the hardware)
-R, --recursive
Recursively copy the directory, retaining non-directory (see above -r ).
--sparse= WHEN
A sparse file 'inclusive `holes'- occupancy 0 bytes, it does not take up any physical block; system calls them as 0 read' to read as many binary files inclusive many consecutive 0 bytes, this can save considerable disk. space and speed. under defaulted case, cp found inspiration in the way of natural source file holes and the associated output file sparse.

WHEN value can be one of the following:

auto
The default behavior: If the input file is sparse, the output file is sparse.
always
Always make the output file sparse. When the input file where the file system does not support sparse file, which is useful, but the output file where the file system needs (support sparse files).
never
Never make the output file sparse. If you need to find an application for this option, let us know.
-s, --symbolic-link
Generate symbolic links instead of copies of non-directories. All source file names must be caused by an error message when absolute (the `/ 'start), unless the purpose of the file in the current directory. This option is only symbolic links are not supported in the system.
-u, --update
If there is a destination with the same or newer modification time, without copying non-directory (file).
-v, --verbose
Print the file name before copying.
-x, --one-file-system
Skip subdirectories from different file systems.

GNU Backup Options

GNU versions of programs like cp , mv , LN , install and patch will cover, change, or destroy (files) before generating a backup file. That file is given by the -b option. They are named by the -V option. In general backup file name is the source file name suffix, this suffix is specified by the -S.

-b, --backup
About generate backup coverage and delete.
-S SUFFIX , --suffix= SUFFIX
Join SUFFIX (suffix) to each backup file. If not specified, use SIMPLE_BACKUP_SUFFIX environment variable. If even SIMPLE_BACKUP_SUFFIX are not set, defaulted is `~ '.
-V METHOD , --version-control= METHOD
Specify how to name the backup file. The METHOD can be `numbered '(or` t' ), `existing '(or` nil'), or `never '(or` simple'). If not specified, use VERSION_CONTROL environment variable value If VERSION_CONTROL is not set, defaulted backup file type is `existing '.

This option corresponding Emacs variable `version-control 'effective the METHOD S is (only accepted abbreviations):

t, numbered
Always produces backup number.
nil, existing
Make numbered backups of files that already have them, simple backups of the others.
never, simple
The total for simple backup.

GNU Standard Options

--help
Print usage and exit.
--version
Print version information and exit.
--
The end of the list of options.

Environmental parameters)

Variables LANG, LC_ALL, LC_COLLATE, LC_CTYPE and LC_MESSAGES have the usual sense. For the GNU version, the variables SIMPLE_BACKUP_SUFFIX and VERSION_CONTROL control backup file naming. As with the above description. 

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11077012.html