CP (Unix) : Operating Modes

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

cp (Unix)

From Wikipedia, the free encyclopedia



This article needs additional citations for verification. Please
help improve this article by adding citations to reliable sources. Unsourced
material may be challenged and removed. (December 2011)

Wikibooks has a book on
the topic of: Guide to
Unix/Commands/File
System Utilities#cp
cp is a UNIX command for copying files and directories. The command has three principal
modes of operation, expressed by the types of arguments presented to the program for copying
a file to another file, one or more files to a directory, or for copying entire directories to another
directory.
The utility further accepts various command line option flags to detail the operations performed.
The two major specifications are POSIX cp and GNU cp. GNU cp has many additional options
over the POSIX version.
[1]

Contents
[hide]
1 Operating modes
2 Usage
3 Option flags
4 Examples
5 Related Unix commands
6 See also
7 References
Operating modes[edit]
Cp has three principal modes of operation. These modes are inferred from the type and count of
arguments presented to the program upon invocation.
When the program has two arguments of path names to files, the program copies the
contents of the first file to the second file, creating the second file if necessary.
When the program has one or more arguments of path names of files and following those an
argument of a path to a directory, then the program copies each source file to the destination
directory, creating any files not already existing.
When the program's arguments are the path names to two directories, cp copies all files in
the source directory to the destination directory, creating any files or directories needed. This
mode of operation requires an additional option flag, typically r, to indicate the recursive
copying of directories. If the destination directory already exists, the source is copied into the
destination, while a new directory is created if the destination does not exist.

You might also like