cp

copy files 

Command


SYNOPSIS

cp [-acfimPpqSv] file1 file2

cp [-acfimPpqSv] file ... directory

cp -R [-acfimPpqSv] source... directory

cp -r [-acfimPpqSv] source... directory


DESCRIPTION

cp copies files to a target named by the last argument on its command line. If the target is an existing file, cp overwrites it; if it does not exist, cp creates it. If the target file already exists and does not have write permission, cp denies access and continues with the next copy.

If you specify more than two path names, the last path name (that is, the target) must be a directory. If the target is a directory, cp copies the sources into that directory with names given by the final component of the source path name.

Normally, the destination file has its file mode (see chmod) set to 777 (that is, readable, writable, and executable by everyone) and sets the file modification time to the present. The -m and -p options can override this behavior.

If a file being copied is a sparse file and the file system to which it is being copied does not support sparse files, cp warns that the resulting file will be larger. If the -i option was also specified, cp asks you if want to expand the file or skip it. The -S option overrides this behavior and expands all sparse files automatically when copying.

Options

-a 

copies the DACLs associated with the specified file along with the file itself.

This option is only available on NTFS file systems.

-c 

prompts you to change the diskette if there is insufficient room to complete a copy operation. The parent directories must already exist on the new target diskette. This option has no effect on systems without floppy drives.

-f 

attempts to replace files that do not have write permission.

-i 

asks you if you want to overwrite an existing file, whether or not the file is read-only.

-m 

sets the modification time, access time, and file mode (see chmod) of each destination file to those of the corresponding source file. The compression and archive bits of the file mode are handled separately. The compression bit for each destination file is always unset, while the archive bit is always set.

-P 

prevents the -m and -p options from copying the file mode (see chmod). This option always sets the archive bit on the copied file.

The behavior of this option is identical to setting the TK_CP_NOPRESERVE environment variable.

-p 

is similar to the -m option, but also sets the owner and group of each destination file to the owner and group of the corresponding source file. Unlike the -m option, the archive bit of all destination files is always unset.

-q 

suppresses warning messages. Error messages are still displayed.

-R 

reproduces the source trees. cp copies all files and subdirectories specified by source.... into directory, making careful arrangements to duplicate special files (FIFO, block special, character special).

-r 

reproduces the source trees, but makes no allowances for special files (FIFO, block special, character special). Consequently, cp attempts to read from a device rather than duplicate the special file. This is similar to, but less useful than, the preferred -R.

-S 

automatically expands sparse files. This lets you make a non-sparse copy of a sparse file.

-v 

prints file names to standard output as they are being processed.


ENVIRONMENT VARIABLES

TK_CP_NOPRESERVE 

when set, this variable prevents the -m and -p options from copying the file mode (see chmod). This option always sets the archive bit on the copied file.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

1 

Failure due to any of the following:

— an argument had a trailing slash (/) but was not a directory
— unable to find a file
— unable to open an input file for reading
— unable to create or open an output file
— a read error occurred on an input file
— a write error occurred on an output file
— the input and output files were the same file
— encountered a fatal error when using -r or -R
Possible fatal -r or -R errors include:
— inability to access a file
— inability to change permissions on a target file
— inability to read a directory
— inability to create a directory
— a target that is not a directory
— source and destination directories are the same
2 

Failure due to any of the following:

— an invalid command line option
— too few arguments on the command line
— a target that should be a directory but is not
— no space left on target device
— out of memory to hold the data to be copied
— inability to create a directory to hold a target file

cannot allocate target string 

cp has no space to hold the name of the target file. Try to free up some memory to give cp more space.

"name" is a directory (not copied) 

You did not specify -r or -R, but one of the names you asked to copy was the name of a directory.

"target name"? 

You are attempting to copy a file with the -i option, but there is already a file with the target name. If you have specified -f, you can write over the existing file by typing y and pressing ENTER; if you do not want to write over the existing file, type n and press ENTER. If you did not specify -f and the file is read only, you are not given the opportunity to overwrite it.

source "name" and target "name" are identical 

The source and the target are actually the same file (for example because of links, on UNIX and POSIX-compliant systems). In this case, cp does nothing.

unreadable directory "name

cp cannot read the specified directory, for example, because you do not have appropriate permissions.


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems. Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016.

The -c, -f, -m, -q and -v options are extensions to the POSIX standard. On Windows systems, the -R and -r options are equivalent since special files (FIFO, block special, character special) are not supported on Windows file systems.


AVAILABILITY

PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC Integrity


SEE ALSO

Commands:
cat, chmod, ln, mv, rm


PTC MKS Toolkit 10.1 Documentation Build 15.