HOME

TheInfoList



OR:

cp is a
shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses Science Biology * Seashell, a hard outer layer of a marine ani ...
command Command may refer to: Computing * Command (computing), a statement in a computer language * command (Unix), a Unix command * COMMAND.COM, the default operating system shell and command-line interpreter for DOS * Command key, a modifier key on A ...
for copying
files File or filing may refer to: Mechanical tools and processes * File (tool), a tool used to remove fine amounts of material from a workpiece. **Filing (metalworking), a material removal process in manufacturing ** Nail file, a tool used to gentl ...
and directories. If the
user Ancient Egyptian roles * User (ancient Egyptian official), an ancient Egyptian nomarch (governor) of the Eighth Dynasty * Useramen, an ancient Egyptian vizier also called "User" Other uses * User (computing), a person (or software) using an ...
has write access to a target file, the command copies the content by opening it in update mode. This preserves the file's
inode An inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribu ...
instead of creating a new file with default permissions. The command was part of
Version 1 Unix Research Unix refers to the early versions of the Unix operating system for DEC PDP-7, PDP-11, VAX and Interdata 7/32 and 8/32 computers, developed in the Bell Labs Computing Sciences Research Center (CSRC). The term ''Research Unix'' first appea ...
, and is specified by
POSIX The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
. The implementation from
GNU GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
has many additional options beyond the POSIX specification. The command is bundled in
GNU Core Utilities The GNU Core Utilities or coreutils is a collection of GNU software that implements many standard, Unix-based shell commands. The utilities generally provide POSIX compliant interface when the environment variable is set, but otherwise offers ...
and is available in the EFI shell.


Options

*-f (force) – specifies removal of each target file if it cannot be opened for write operations; removal precedes any copying * -H (dereference) – follows
symbolic link In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a path thereto. Symbolic links are supported by POSIX and by most Unix-like operating syste ...
s so that the destination has the target file rather than a link to the target *-i (interactive) – prompts user to overwrite each target file that clashes with a source file *-n (no
clobbering In computing, clobbering is the act of overwriting a resource such as a file, processor register or a region of memory, such that its content is lost. Generally, the term is used in the context of unintentional loss of information, but it can be ...
) – prevents overwriting files *-p (preserve) – preserves metadata of each source file in the destination; including: time of last modification and last access, ownership, and file permissions *-R or -r (recursive) – copy directories recursively


Modes

The command has three principal modes of operation as inferred from command-line arguments.


Copy file

For a path to an existing file followed by a path that does ''not'' refer to an existing directory, the file at the first path is copied to the second path. cp fHip--] sourcefile targetfile


Copy files to directory

For one or more paths to existing files followed by a path to an existing directory, the files are copied to the directory. cp fHip -sourcefile... targetdirectory


Copy directory

With the recurse command-line option, typically , a path to an existing directory and a second path, the files of the directory are copied to the second path. If the second path refers to nothing, the source directory is copied to that path. If the second path refers to an existing directory, the source directory is copied into the destination directory as a subdirectory. cp -r, -R fHip -sourcedirectory... targetdirectory


Examples

This copies file prog.c to file prog.bak. If prog.bak does not already exist, this creates it. If it does exist, its content will be replaced. cp prog.c prog.bak This copies the files jones and smith into the pre-existing directory clients. cp jones smith clients This copies file smith to a file named smith.jr. Instead of creating a file with the current date and time stamp, the command copies the date and time from the original. The copy also receives other metadata from the original including access control protection. cp -p smith smith.jr This reclusively copies the directory clients, including its files, subdirectories, and the files in those subdirectories, to a new directory customers/clients. cp -R clients customers Some implementations behave differently in recursive mode, depending on the termination of the directory path. Using cp -R clients/ customers in the GNU implementation behaves as above. However, with a BSD implementation, it copies the ''contents'' of the clients directory, instead of the directory clients itself. The same happens in both GNU and BSD implementations if the path of the source directory ends in . or .. (with or without trailing slash).


See also

* * * * * * * progress – Linux tool to show progress for cp, mv, dd * * * *


References


External links

* * * * * * * {{Core Utilities commands Standard Unix programs Unix SUS2008 utilities File copy utilities Plan 9 commands Inferno (operating system) commands IBM i Qshell commands