-a --archive don't follow symbolic links
--preserve=link recursively
preserve mode,ownership,timestamps
| Handing existing destination
|
|---|
-i --interactive prompt before overwrite
| -u --update only when the source is newer or dest doesn't exist
| -f --force if existing dest cannot be opened, remove it and try again.
| --remove-destination remove dest before opening it (contrast with --force).
|
backup (not )
--backup[=control] make a backup of dest before writing to that filename.
none, off never make backups (even with --backup )
| numbered, t | make numbered backups
| existing, nil | numbered if numbered backups exist, simple otherwise
| simple, neversic | 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.
| -S --suffix=suffix backup suffix, default is ~. as with vi.
| -b ⌘
backup : cp -b source dest
|
| Link handling
|
|---|
-L --dereference follow symbolic links
| -P --no-dereference don't follow symbolic links
| -d | --no-dereference --preserve=link
| -H | follow command-line symbolic links
| -s --symbolic-link imake symbolic links instead of copying
| -l --link link files instead of copying
| | Attributes
|
|---|
-p preserve mode, ownership, timestamps
| --preserve[=attr_list] preserve specified attributes
default: mode, ownership, timestamps, security, contexts links, all
--no-preserve=attr_list| don't preserve the specified attributes
| |
| --parents use full source name under directory
| -R -r --recursive copy directories recursively
--sparse=auto|always|never control creation of sparse files
auto | if SOURCE is detected as sparse
| always | if the SOURCE has enough strings of zeros
|
|
| additional
|
|---|
--strip-trailing-slashes | remove any trailing slashes from each SOURCE argument
| -t --target-directory=dir all source arguments get copied into DIRECTORY
| -T --no-target-directory treat dest as a normal file
| --copy-contents| copy contents of special files when recursive
| -x --one-file-system stay on this file system
| -Z --context=context set security context of copy to context
-v --verbose display what is being done
| --help | display this help and exit
| --version| output version information and exit
| | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|---|
| | | | | |
BSD version i.e. Mac OS X (darwin) lion includes -X
cp [-R [-H|-L|-P]] [-f|-i|-n]†
[-v] [-a|-p] [-X]
| source target
| the contents of the source are copied to the target.
Files that begin with a dot (ex: .bashrc, .profile) are not copied, use cp .* target.
| cp [-R [-H|-L|-P]]
[-f|-i|-n]
[-v] [-a| -p] [-X]
source file… target_directory
source files are copied to the target_directory.
| | | |
An attempt to copy a file to itself fails.
-v | verbose, showing files as they are copied.
|
-aSafe; i.e. Same as -pPR, preserves structure and attributes of files but not directory structure.
| -i interactivly prompt to standard error before overwriting an existing file, y continues.
Not the default an alias cp='cp -i' is frequently entered into .profile
Overrides previous -n (don't overwrite).
| -f | 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 -i or -n options.)
| -n | Do not overwrite an existing file.
(-n overrides any previous -f or -i options.)
Not the default
| -p | 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 .profile
File mode is preserved without specifing -p.
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.
| -X| Do not copy Extended Attributes (EAs) or resource forks
| |
| -R Recursively copy the directory and the entire subtree.
If source_file ends in /, the contents of the directory are copied rather than the directory itself.
i.e.
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
| -P | not are followed (with -R. Default.
| -L | links followed.
| -H | 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.
In the cp fileDirectory form, target_directory must exist,
unless
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 umask.
If the source file has user ID bit set, it is removed unless both the source file and the destination file are owned by the same user.
If the source file has group ID set , it 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 user ID
and group ID are set, all of the above conditions must be fulfilled or both are removed.
Appropriate permissions are required for file creation or overwriting.
Symbolic links are followed unless -R is set.
-H or -L (in conjunction with -R)
cause symbolic links to be followed as described above.
-H, -L and -P are ignored unless -R
is specified.
These options override each other and the last one specified is used.
Errors
cp: failed to preserve ownership for '/boot/etc/rsyslog.conf': Operation not permitted
The volume /boot is a FAT filesystem and does not support ownership. The file is copied and to timestamp ism preserved!
See mv, rcp, umask,
fts, symlink