cp - copy files and directories
cp [option]… [-T] source dest
cp [option]… source… directory
cp [option]… -t directory source…
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
| don't follow symbolic links|
| Handing existing destination
| prompt before overwrite
| copy only when the SOURCE file is newer or the destination file doesn't exist
| if an existing destination file cannot be opened, remove it and try again
| remove destination file before opening it (contrast with --force)
| make a backup of each existing destination file
| backup suffix, default is |
| Link handling
|follow command-line symbolic links
| make symbolic links instead of copying
| link files instead of copying
| follow symbolic links
| don't follow symbolic links
| preserve |
mode, ownership, timestamps
| preserve the specified attributes |
mode, ownership, timestamps, security, contexts links, all
| don't preserve the specified attributes
| use full source file name under DIRECTORY
| copy directories recursively
| control creation of sparse files
| if SOURCE file is detected as sparse
| if the SOURCE file has enough strings of zeros
| remove any trailing slashes from each SOURCE argument
| copy all SOURCE arguments into DIRECTORY
| treat DEST as a normal file
| copy contents of special files when recursive
| display what is being done
| stay on this file system
| set security context of copy to |
|display this help and exit
| output version information and exit
|never make backups (even if --backup is given)
|make numbered backups
|numbered if numbered backups exist, simple otherwise
|always make simple backups
As a special case, 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.
BSD version i.e. Mac OS X (darwin) lion includes
cp [-R [-H|-L|-P]] [-f|-i|-n]†
[-v] [-a|-p] [-X]
|the contents of the |
source are copied to the
Files that begin with a dot (ex:
.bashrc, .profile) are not copied, use
cp .* target.
cp [-R [-H|-L|-P]]
[-v] [-a| -p] [-X]
source file… target_directory
source files are copied to the
An attempt to copy a file to itself fails.
|verbose, showing files as they are copied.|
|Safe; i.e. Same as |
-pPR, preserves structure and attributes of files but not directory structure.
| interactivly prompt to standard error before overwriting an existing file, y continues.|
Not the default an
alias cp='cp -i' is frequently entered into
-n (don't overwrite).
|force overwrite an existing file, without prompting for confirmation even if its mode is not writable existing access rights will be retained.
-f overrides any previous
|Do not overwrite an existing file.
-n overrides any previous
Not the default
| preserve the modification time, access time, file flags,
Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks|
Not the default an
alias cp='cp -p' is frequently entered into
File mode is preserved without specifing
If the user ID and group ID cannot be preserved, no error message
is displayed and the exit value is not affected ( ex:
cp /user/you/file mycopy )
If the source file has both "set user ID" and "set group ID" and
either cannot be preserved, neither bits are preserved.
If the destination file exists, its contents are overwritten, but its mode, user ID, and group ID are unchanged unless
-p was specified.
|Do not copy Extended Attributes (EAs) or resource forks
|Recursively copy the directory and the entire subtree. |
source_file ends in
/, the contents of the directory are copied rather than the directory itself.
cp -R /your/source .
will cause a
source directory to be created
cp -R /your/source/ .
will cause the files in the source directory to be copied into the current directory
|Symbolic Link processing
|not are followed (with |
|not followed when encountered in the tree traversal.|
Followed if on the command line .
Created directories have the same mode as the corresponding source directory.
Symbolic links are copied, rather than indirected through.
Hard linked files are copied files, This causes additional space to be required and the files in the destination directory are not longer linked.
To preserve hard links, use tar,
cpio, or pax .
New special files are created rather than copying them as normal files.
cp fileDirectory form,
target_directory must exist,
a directory is the source and
-R is specified.
The mode of the destination file (if it does not exist) is the mode of the source modified by the
If the source file has its set user ID bit on, that bit is removed unless
both the source file and the destination file are owned by the same user.
If the source file has its set group ID bit on, that bit is removed
unless both the source file and the destination file are in the same
group and the user is a member of that group.
If both the set user ID
and set group ID bits are set, all of the above conditions must be fulfilled or both bits are removed.
Appropriate permissions are required for file creation or overwriting.
Symbolic links are followed unless
-R is set.
-L (in conjunction with
cause symbolic links to be followed as described above.
-P are ignored unless
These options override each other and the last one specified is used.
Exits 0 on success, and >0 if an error occurs.
See mv, rcp, umask,