{ cp | copy } [ -f ] [ -h ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
{ cp | copy } [ -f ] [ -h ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
{ cp | copy } [ -f ] [ -h ] [ -i ] [ -p ] [ -- ] { -r | -R } SourceDirectory ... TargetDirectory
The cp command copies the source file specified by the SourceFile parameter to the destination file specified by the TargetFile parameter. Also, the cp command can copy the source files specified by the SourceFile parameter (or directories named by the SourceDirectory parameter) to the directory specified by the TargetDirectory parameter.
Note: If one of the source parameters is a directory, you need to specify one of the -r or -R flags.
If any directories are created by the cp command during the copying process, the newly created directory will have the same mode as the corresponding source directory.
You can also copy special device files. The preferred option for accomplishing this is the -R flag. Specifying -R causes the special files to be re-created under the new path name. Specifying the -r flag causes the cp command to attempt to copy the special file to a regular file.
-f | Specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command. |
-h | Forces the cp command to copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point. |
-i | Prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y , the cp command continues. Any other answer prevents the cp command from overwriting the file. |
-p | Duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
If the user ID or group ID cannot be duplicated, the file permission bits S_ISUID and S_ISGID will be cleared. The target file will not be deleted if these characteristics cannot be preserved. Access control lists (ACLs) associated with the SourceFile are also preserved. See "Managing Protected Resources with Access Control" in AIX Version 4.3 System User's Guide: Operating System and Devices to learn more about ACLs. |
-r | Copies file hierarchies under the file or directory specified by the SourceFile or SourceDirectory parameter (recursive copy). The -r flag processes special files in the same manner as regular files. |
-R | Copies file hierarchies under the regular files and directories from the directory specified by the SourceFile or SourceDirectory parameter to the directory specified by the TargetDirectory parameter. Special file types, such as first-in, first-out (FIFO) files and block and character device files, are re-created instead of copied. Symbolic links are followed unless the -h flag is specified. (The -R flag is preferred to the -r flag.) |
-- | Indicates that parameters following the -- (dash, dash) flag are to be interpreted as file names. This null flag allows the specification of file names that start with a - (minus sign). |
This command returns the following exit values:
0 | All files were copied successfully. |
>0 | An error occurred. |
cp prog.c prog.bakThis copies prog.c to prog.bak . If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
cp jones /home/nick/clientsThis copies the jones file to /home/nick/clients/jones .
cp -p smith smith.jrThis copies the smith file to the smith.jr file. Instead of creating the file with the current date and time stamp, the system gives the smith.jr file the same date and time as the smith file. The smith.jr file also inherits the smith file's access control protection.
cp /home/janet/clients/* /home/nick/customersThis copies only the files in the clients directory to the customers directory.
cp -R /home/nick/clients /home/nick/customersThis copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
cp jones lewis smith /home/nick/clientsThis copies the jones , lewis , and smith files in your current working directory to the /home/nick/clients directory.
cp programs/*.c .This copies the files in the programs directory that end with .c to the current directory, signified by the single . (dot). You must type a space between the c and the final dot.
/usr/bin/cp | Contains the cp command. |
/usr/bin/copy | Contains the copy command. |
The cpio command, link command, ln command, mv command, unlink command.
File Systems and Directories Overview in AIX Version 4.3 System User's Guide: Operating System and Devices.
National Language Support Overview for System Management in AIX Version 4.3 System Management Guide: Operating System and Devices.