cp - Copy a file

Format

If the variable _UNIX03=YES is set:

cp [-cfimMUv] [-p|-F format |-B|-T|-X[-I]] [-W seqparms=params] [-Z] [-O -u | c=codeset]file1 file2

cp [-ACcfimMUv] [-p | -F format|-B|-T|-X[-II]] [-s suffix] [-Z] [[-O -u | c=codeset] file file ... directory

cp -r [-H|-L|-P] [-cfimp] [-Z] [-O -u | -c=codeset] source... directory

cp -r [-H|-L|-P] [-cfimp][-Z] [-O -u | -ccodeset] source... directory

If the variable _UNIX03 is unset or not YES:

cp [-cfimMUv] [-p|-F format|B|T|X[I]] [-P params] [-W seqparms=params] [-Z] [-O u | c=codeset] file1 file2

cp [-ACcfimMUv] [-p|F format|B|T|X[I]] [-S suffix] [-Z] [[-O -u | -ccodeset] codeset] file ... file ... directory

cp -r [-H|-L] [-cfimp] [-Z] [[-O -u | -ccodeset] codeset] source... directory

cp -r [-H|-L] [-cfimp] [-Z] [[-O -u |-ccodeset] codeset] 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 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 that are given by the final component of the source path name.

You can also use cp to copy files to and from MVS™ data sets. If you specify more than one file to be copied, the target (last path name on command line) must be either a directory or a partitioned data set. If the target is an MVS partitioned data set, the source cannot be a UNIX directory.

cp does not support the copying to or from generation data groups (GDGs). To use those MVS data sets, the user must specify the real data set name. cp also does not support copying to a temporary PDSE.

When copying records, the string " \n" is copied the same way as the string "\n": both are read back as "\n", where "\n" indicates that z/OS XL C++ will write a record containing a single blank to the file (the default behavior of z/OS XL C/C++). All other blanks in your output are read back as blanks, and any empty (zero-length) records are ignored on input. However, if the environment variable _EDC_ZERO_RECLEN is set to Y before cp is called, an empty record is treated as a single newline character and is not ignored. Also, if _EDC_ZERO_RECLEN is set to Y, a single newline character is written to the file as an empty record, and a single blank will be represented by " \n".

You can copy:
  • One file to another file in the working directory.
  • One file to a new file on another directory.
  • A set of directories and files to another place in your file system.
  • A UNIX file to an MVS data set.
  • An MVS data set to a file system.
  • An MVS data set to an MVS data set.

Options

-A
Specifies that all suffixes (from the first period to the end of the target) be truncated. -A has precedence over -M and -C options. -s will be turned off if -A is the last option specified.
-B
Specifies that the data to be copied contains binary data. When you specify -B, cp operates without any consideration for <newline> characters or special characteristics of DBCS data. (This type of behavior is typical when data is copied across a UNIX system.) Because -B is mutually exclusive with -F, -x, and -T, you will get an error if you specify more than one of these options.
-C
Specifies truncating the file name to 8 characters to meet the restriction in the MVS data set member.
-c (UNIX to UNIX only)
Prompts you to change the disk if there is not enough room to complete a copy operation. This option has no effect on systems without disk drives. The parent directories must exist on the new target diskette.
-F format
Specifies whether the file is to be treated as binary, text, or record file format when copied; for text files, specifies the end-of-line delimiter. Also sets the file format to format if the target is a UNIX file. For text files, when copying from UNIX to MVS, the end-of-line delimiter is stripped. When copying from MVS to UNIX, the end-of-line delimiter is added. (Code page IBM-1047 is used to check for end-of-line delimiters.) Record file format files are treated as if they were binary files.

If -F is used when copying from UNIX to UNIX, cp sets only the target file format and does not replace the end-of-line delimiters.

If setting format fails, a warning is displayed but cp will continue to copy any remaining files that were specified to be copied.

-F is mutually exclusive with -B, -x, -p, and -T. If you specify one of these options with -F, you will get an error. If -F is specified more than once, the last -F specified is used.

For format, you can specify:
not
Not specified.
bin
Binary data.
rec
Record. (File data consists of records with prefixes. The record prefix contains the length of the record that follows. From the shell command perspective, files with this format will be treated as if they were binary files.)
Or, you can specify the following text data delimiters:
nl
Newline character.
cr
Carriage return.
lf
Line feed.
crlf
Carriage return followed by line feed.
lfcr
Line feed followed by carriage return.
crnl
Carriage return followed by new line.
-F
Attempts to remove and replace a UNIX destination file that cannot be opened.
-H
Follows symbolic links that are specified as source operand on the command line. Symbolic links that are encountered in the tree traversal are not followed. This is the default behavior when the -R or -r option is specified but none of the -H, -L or -P options are specified.
Restriction: This option can only be used with the -R or the -r option.
-i
When copying to a UNIX target, -i asks you if you want to overwrite an existing file, whether the file is read-only.
-L
Follows symbolic links that are specified as source operand on the command line and those encountered in the tree traverse.
Restriction: This option can only be used with the -R or the -r option.
-M
Specifies that some characters of the file name are converted during the copy process between a UNIX file and an MVS data set member. Characters are converted as follows:
  • _ (underscore) in UNIX is converted to @ in MVS data set members and vice versa.
  • . (period) in UNIX is converted to # in MVS data set members and vice versa.
  • - (dash) in UNIX is converted to $ in MVS data set members and vice versa.
-F (UNIX to UNIX only)
Sets the modification and access time of each destination file to that of the corresponding source file. Typically, cp sets the modification time of the destination file to the present.
-I (UNIX to MVS only)
When the specified file has an alias and the file is copied from UNIX to MVS, the alias information is also copied. If the -I option is specified when the data set that is copied from MVS to z/OS UNIX does not have an alias, that option is ignored.
Restriction: The -I option can only be used with the -X option.
-O u | c=codeset
Allow automatic conversion on source and target files.
-O u
If the target exists and is not empty or tagged, cp will not change the target's tag in order for the target to be a candidate for automatic conversion.

For new targets and existing, untagged, empty files, this option has no effect and cp behaves the same as the default. For a description of the default behavior, see Automatic conversion and file tagging behavior for cp.

If you are using cp to copy from a UNIXan MVS file to a data set, if the source is a tagged text file, then it might be a candidate for automatic conversion.

If you are copying executables from or to MVS, the automatic conversion is disabled for both source and target.
-O c=codeset
For a detailed description of the behavior of this option on cp, see Automatic conversion and file tagging behavior for cp.

codeset can be a code set name known to the system or the numeric coded character set identifier (CCSID). If a code set name exists, the numeric CCSID associated with that name is used. Note that the command iconv -l lists existing CCSIDs along with their corresponding code set names.

To prevent the corruption of text files, cp will fail if it cannot set the tag to text or code set.

If automatic conversion is not set properly or if the source is not tagged properly, the target might end up with a tag code set that does not match the file content.

-P
If _UNIX03 is YES, does not follow any symbolic links, neither those specified as source operand on the command line not those encountered in the tree traverse.
Restriction: This option can only be used with the -R or the -r option.
-P params
If _UNIX03 is unset or not YES, then the -P option will be treated as specifying parameters needed to create a new sequential data set if one does not exist. You can specify the RECFM, LRECL, BLKSIZE, and SPACE in the format the CRTL fopen() function uses.
SPACE=(units,(primary,secondary) where the following values are supported for units:
  • Any positive integer indicating BLKSIZE.
  • CYL (mixed case).
  • TRK (mixed case).
For example:
SPACE=(500,(100,500)) units, primary, secondary
SPACE=(500,100) units and primary only

For information about how to specify these parameters, see z/OS XL C/C++ Programming Guide.

CRTL fopen() arguments: LRECL specifies the length, in bytes, for fixed-length records and the maximum length for variable-length records. BLKSIZE specifies the maximum length, in bytes, of a physical block of records. RECFM refers to the record format of a data set and SPACE indicates the space attributes for MVS data sets.

-p (UNIX to UNIX only)
Preserves the modification and access times (as the -m option does). In addition, it preserves the file mode, file format, owner, and group owner, if authorized. It also preserves extended attributes. It preserves the ACLs of files and directories, if possible. The ACLs are not preserved if a file system does not support ACLs.

-p is mutually exclusive with -F. If you specify both, you will get an error message.

-R (UNIX to UNIX only)
Clones the source trees. cp copies all the files and subdirectories that are specified by source... into directory, making careful arrangements to duplicate special files (FIFO, character special). cp only follows symbolic link specified as source operand on the command line.
-r (UNIX to UNIX only)
Clones the source trees, but makes no allowances for special files (FIFO, 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 d=suffix|a=suffix
  • d=suffix removes the specified suffix from a file.
  • a=suffix appends the specified suffix to a file.
-S has precedence over -M and -C. It also turns off the -A option (if -S is the last specified option).
-T
Specifies that the data to be copied contains text data. See Usage notes for details on how to treat text data. This option looks for IBM-1047 end-of-line delimiters, and is mutually exclusive with -F, -X, and -B. That is, you will get an error if you specify more than one of these options.

-T is ignored when if you are copying data across UNIX file systems.

-U
Keeps file names in uppercase when copying from MVS data set members to UNIX files. The default is to make file names lowercase.
-v
Verbose
-W seqparms=params
Specifies the parameters that are needed to create a sequential data set if one does not exist. You can specify the RECFM, LRECL, BLKSIZE, and SPACE in the format the CRTL fopen() function uses.
SPACE=(units,(primary,secondary) where the following values are supported for units:
  • Any positive integer indicating BLKSIZE.
  • CYL (mixed case).
  • TRK (mixed case).
    For example:
    SPACE=(500,(100,500)) units, primary, secondary
    SPACE=(500,100) units and primary only
For information about how to specify these parameters, see z/OS XL C/C++ Programming Guide.

CRTL fopen() arguments: LRECL specifies the length, in bytes, for fixed-length records and the maximum length for variable-length records. BLKSIZE specifies the maximum length, in bytes, of a physical block of records. RECFM refers to the record format of a data set and SPACE indicates the space attributes for MVS data sets.

This option is the same as -P params with _UNIX03 unset or not YES. If multiple -P params and -W are specified, the value of the last one specified on the command will be used.

-X
Specifies that the data to be copied is an executable. Cannot be used with -F, -T, or -B.
-Z
Specifies that error messages are not to be displayed when setting ACLs on the target. The return code will be zero. If default behavior is used to set the file tag, failure is suppressed. For a description of the default behavior, see Automatic conversion and file tagging behavior for cp.

If you do not specify either -F|B|T or X, cp will first check the format of the MVS data set indicated and then try to determine the type of file.

The -P option on cp does not affect file tagging.

Automatic conversion and file tagging behavior for cp

The following tables describe the behavior of file tagging and automatic conversion for various source and target scenarios depending on whether the -O option is specified on the cp command.
Table 1. Copying files to files by using the default (without the -0 option)
S If the target file system supports setting file tags... If the target file system does not support setting file tags (For example, NFS)... With -O u option With -O c=codeset option
File tagging Target file is tagged the same as the source file. The tag of an existing target is not changed.

A new target is created with a tag according to the file system's attributes (MOUNT parameter can specify TAG).

The tag of the target is not changed.

(The source or target file is a candidate for automatic conversion when its TXTFLAG is tagged TEXT.)

Target's TXTFLAG is set to TEXT and its code set is set to codeset.
Automatic conversion Disabled for source and target files Allowed for source and target files
Table 2. Automatic conversion and file tagging behavior for cp: Copying files to files
  Default (without -O option) With -O u option With -O c=codeset option
If the target file system supports setting file tags... If the target file system does not support setting file tags (For example, NFS)...
File tagging Target file is tagged the same as the source file. An existing target's tag is unchanged.

A new target is created with a tag according to the file system's attributes (MOUNT parameter can specify TAG).

Target's tag is unchanged.

(The source or target file is a candidate for automatic conversion when its TXTFLAG is tagged TEXT.)

Target's TXTFLAG is set to TEXT and its code set is set to codeset.
Automatic conversion Disabled for source and target files Allowed for source and target files
Table 3. Automatic conversion and file tagging behavior for cp: Copying MVS data sets to files
  Default (without -O option) With -O u option With -O c=codeset option
If the target file system supports setting file tags... If the target file system does not support setting file tags (For example, NFS)...
If the SOURCE is text:
File tagging Target is set to UNTAG An existing target's tag is unchanged.

A new target is created with a tag according to the file system's attributes (MOUNT parameter can specify TAG).

Target's tag is unchanged Target's TXTFLAG is set to TEXT and its code set is set to codeset.
Automatic conversion Disabled for target file Allowed for target file

(The target file is a candidate for automatic conversion when its TXTFLAG is tagged TEXT.)

If the SOURCE is binary or executable:
File tagging Target is set to UNTAG Target's tag is unchanged Target's TXTFLAG is set to BINARY and its code set is set to codeset.
Automatic conversion Disabled for target file
Table 4. Automatic conversion and file tagging behavior for cp: Copying files to MVS data sets
  Default (without -O option) With -O u option With -O c=codeset option
If the SOURCE is text or binary:
File tagging Not applicable for target data set
Automatic conversion Disabled for source file Allowed for source file

(The source file is a candidate for automatic conversion when its TXTFLAG is tagged TEXT.)

Disabled for source file
If the SOURCE is executable:
File tagging Not applicable for target data set
Automatic conversion Disabled for source file

Limits and requirements

In general:

  1. To specify an MVS data set name, precede the name with double slashes (//). For example, to specify the fully qualified data set names 'turbo.gammalib' and 'turbo.gammalib(pgm1)', write:
    "//'turbo.gammalib'"
    "//'turbo.gammalib(pgm1)'"
    The same goes for data set names that are not fully qualified:
    //turbo
  2. For PDS (partitioned data set) or PDSE (partitioned data set extended), to avoid parsing by the shell, the name should be quoted or minimally, the parenthesis should be escaped. For example, to specify 'turbo(pgm1)', use quotes:
    "//turbo(pgm1)"  
    or escape the parenthesis:
    //turbo\(pgm1\)

    As indicated, a fully qualified name must be surrounded with single quotation marks (as is done within TSO). To prevent the single quotation marks from being interpreted by the shell, they must be escaped or the name must be placed within regular quotation marks. See the 'turbo.gammalib' examples.

  3. If you specify a UNIX file as source and the MVS data set (target) does not exist, a sequential data set will be created. If the partitioned data set exists, the UNIX file will be copied to the partitioned data set member.
  4. If source is an MVS data set and target is a UNIX directory, the UNIX directory must exist.
  5. You cannot have a UNIX directory, partitioned data set, or sequential data set as source if the target is a partitioned data set.
  6. To copy all members from a partitioned data set, you can specify the partitioned data set as source and a UNIX directory as target.
MVS data set naming limitations: The naming of MVS data sets has some limitations.
  • Data set names can only contain uppercase alphabetic characters (A-Z). Lowercase characters will be converted to uppercase during any copies to MVS data sets.
  • Data set names can contain numeric characters 0-9 and special characters @, #, and $.
  • Data set names cannot begin with a numeric character.
  • A data set member name cannot be more than 8 characters. If a file name is longer than 8 characters or uses characters that are not allowed in an MVS data set name, the file is not copied. You can use the -C option to truncate names to 8 characters.
Limitations: UNIX to MVS data set: The limitations are as follows:
  1. If you specify a sequential MVS data set that is in undefined record format, the file is copied as binary.
  2. If you specify a PDSE that is in undefined record format, the first file successfully copied determines in what format files will be copied. Note that PDSE does not allow a mixture of formats. If the first successfully copied file is an executable, the PDSE will have program objects only and all other files will fail. On the other hand, if the first file is data, then all files are copied as binary.
  3. If you specify a PDS that is in undefined record format, UNIX executables are saved as PDS load modules. All other files are copied as binary.
  4. If you specify an MVS data set that is either in variable length or fixed record length and you have not set the file format, text files are copied as text, binaries as binary, and executables as binary. (IBM-1047 end-of-line delimiters are detected in the data)
  5. If you set the file format, the set value is used to determine if data is binary, text, or record file format.
Limitations: MVS data set to UNIX: The limitations are as follows:
  1. If an UNIX file does not exist, one is created using 666 mode value, whether the data to be copied is binary or text:
    666 mode value:  owner(rw-)  group(rw-)  other(rw-)
    If the data to be copied is a shell script or executable in a PDS or PDSE with undefined record format, the UNIX file is created using 777 mode value:
    777 mode value:  owner(rwx)  group(rwx)  other(rwx)
  2. If a UNIX file exists and the file format is set, cp copies the file as that format. Otherwise,
    • Load modules (PDS) are stored as UNIX executables and program objects (PDSE) are copied because they are the same as executables;
    • Data within data sets of undefined record format are copied as binary if the data is not a program object or load module;
    • Data found within data sets of fixed length or variable record length are copied as text. (IBM-1047 end-of-line delimiters are detected in the data)
Limitations: MVS to MVS: The limitations are as follows:
  1. Options -A, -C, -F, and -S are ignored.
  2. If target and source are in undefined record format (and neither is a sequential data set), cp will attempt to copy the data as a load module. If that fails, then cp will copy the data as binary.
  3. If target and source are in undefined record format and either is a sequential data set, cp copies the data as binary.
  4. If the source has a fixed or variable record length and the target is in undefined record format, cp copies the data as binary.
  5. If the source is in undefined record format and the target has a fixed or variable record length, cp copies the data as binary.
  6. If both source and target are in fixed or variable record length, cp copies the data as text.
Limitations: Copying executables into a PDS: The limitations are as follows:
  1. A PDS cannot store load modules that incorporate program management features.
  2. c89, by default, produces objects using the highest level of program management.
  3. If you plan on copying a load module to a PDS, you can use a prelinker, which produces output compatible with linkage editor. Output generated by a linkage editor generated can be stored in a PDS.

Table 5 is a quick reference for determining the correct use of options with cp.

Table 5. Options that are allowed for cp: File to File and File (multiple files) to directory
Source/target Options allowed Options ignored Options failed
UNIX file/UNIX file Ffip ABCMPSTUX  
UNIX file/sequential data set BFiPT ACfMpSU X
UNIX file/PDS or PDSE member BFiTX ACfMPpSU  
Sequential data set/UNIX file BFfiTU ACMPpS X
Sequential data set/sequential data set BFiPT ACfMpSU X
Sequential data set/PDS or PDSE member BFiT ACfMPpSU X
PDS or PDSE member/UNIX file BFfiTUX ACMPpS  
PDS or PDSE member/sequential data set BFiPT ACfMpSU X
PDS or PDSE member/PDS or PDSE member BFiTX ACfMPpSU  
UNIX file/UNIX directory ACFipS BMPTUX  
PDSE or PDSE member/UNIX directory BFfiMSTUX ACMPp  
UNIX file/partitioned data set ABCFiMSTX fPpU  
PDS or PDSE member/partitioned data set BFiTX ACfMPpSU  
Partitioned data set/UNIX directory ABCFfiMSTUX Pp  

The tables that follow indicate the kind of copies that are allowed by using cp.

Table 6. Copies that are allowed for cp: File to File
Source Target Allowed
UNIX file, sequential data set, or partitioned data set member UNIX file, sequential data set, or partitioned data set member Yes
UNIX directory UNIX directory No (unless cp is used with -r or -r)
Partitioned data set UNIX directory (dir) NOTE: results in each member of data set are moved to dir. Yes
UNIX directory Partitioned data set No
Partitioned data set Partitioned data set No
UNIX file or partitioned data set member UNIX directory (must exist) or partitioned data set Yes
Partitioned data set member Partitioned data set Yes
Table 7. Copies allowed for cp: File... (multiple files) to directory
Source Target Allowed
Any combination of UNIX file or partitioned data set member UNIX directory or Partitioned data set Yes
Any combination of UNIX directory or sequential data set Partitioned data set or UNIX directory No
Partitioned data set UNIX directory Yes
Partitioned data set Partitioned data set No

Usage notes

You cannot copy a UNIX file to a PDS or PDS/E data set with the cp command if the PDS or PDS/E data set has already been opened by another user or job. For example, if the data set posix.test.pdse is being viewed by ISPF browse, the following cp command will fail:
cp test_file "//'posix.test.pdse(member)'" 
UNIX to MVS:
  1. To copy from UNIX to a partitioned data set, you must allocate the data set before doing the cp.
  2. If an MVS data set does not exist, cp will allocate a new sequential data set of variable record format.
  3. For text files, all <newline> characters are stripped during the copy. Each line in the file ending with a <newline> character is copied into a record of the MVS data set. If text file format is specified or already exists for the source file, that file format will be used for end-of-line delimiter instead of <newline>. Note that cp looks for IBM-1047 end-of-line delimiters in data.

    You cannot copy a text file to an MVS data set that has an undefined record format.

    • For an MVS data set in fixed record format, any line copied longer than the record size will cause cp to fail with a displayed error message and error code. If the line is shorter than the record size, the record is padded with blanks.
    • For an MVS data set in variable record format: Any line copied longer than the largest record size will cause cp to fail with a displayed error message and error code. Record length is set to the length of the line.
  4. For binary files, all copied data is preserved:
    • For an MVS data set in fixed record format, data is cut into chunks of size equal to the record length. Each chunk is put into one record. The last record is padded with blanks.
    • For an MVS data set in variable record format, data is cut into chunks of size equal to the largest record length. Each chunk is put into one record. The length of the last record is equal to length of the data left.
    • For an MVS data set in undefined record format, data is cut into chunks of size equal to the block size. Each chunk is put into one record. The length of the last record is equal to the length of the data left.
  5. For load modules, the partitioned data set specified must be in undefined record format. Otherwise the executable will not be copied.
  6. If more than one file name is the same, the file is overwritten on each subsequent copy.
  7. If a UNIX file name contains characters that are not allowed in an MVS data set, it will not be copied. If the UNIX file name has more than 8 characters, it can not be copied to an MVS data set member. (See the -ACMS options for converting file names)
  8. You are not allowed to copy files into data sets with spanned records.
  9. PDSE cannot have a mixture of program objects and data members. PDS allows mixing, but it is not recommended.
  10. Special files such as external links and FIFO will not be copied to MVS data sets. However, you can copy character special files to MVS data sets.
  11. If a file is a symbolic link, cp copies the resolved file, not the link itself.
  12. UNIX file attributes are lost when copying to MVS. If you want to preserve file attributes, you should use the pax utility.
MVS to UNIX:
  1. If the target UNIX file exists, the new data overwrites the existing data. The mode of the file is unchanged (except the S_ISUID and S_ISGID bits are turned off).
  2. If the specified UNIX file does not exist, it will be created using 666 mode value if binary or text (this is subject to umask). If the data to be copied is a shell script or executable, the UNIX file will be created with 777 mode value (also subject to umask).
  3. For an MVS data set in variable record format RECFM(VB) or undefined record format RECFM(U), trailing blanks are preserved when copying from MVS to UNIX. For an MVS data set in fixed record format, trailing blanks are not preserved when copying from MVS to UNIX.
  4. When you copy MVS data sets to text files in the z/OS® UNIX file system, a <newline> character is appended to the end of each record. If trailing blanks exist in the record, the <newline> character is appended after the trailing blanks. If the file format option is specified or the target file has the file format set, that file format is used as the end-of-line delimiter instead of <newline>.
  5. When you copy MVS data sets to UNIX binary files, the <newline> character is not appended to the record.
  6. You cannot use cp to copy data sets with spanned record lengths.
  7. Due to an XL C/C++ runtime restriction, when copying a file from a file system to an MVS sequential data set with the same name and case, you must prefix the file in the file system with "./". For example:
    cp ./SMPL.DATA   "//'SMPL.DATA'"

Examples

  1. If _UNIX03 is unset or not 'YES, to specify -P params for a nonexisting sequential target:
    cp -P "RECFM=U,space=(500,100)" file "//'turbo.gammalib'"
    This cp command is equivalent to:
     cp -W "seqparms='RECFM=U,space=(500,100)'" file "//'turbo.gammalib'"
  2. To copy file f1 to a fully qualified sequential data set 'turbo.gammalib' and treat it as a binary:
    cp -F bin f1 "//'turbo.gammalib'"
  3. To copy all members from a fully qualified PDS 'turbo.gammalib' to an existing UNIX directory dir:
    cp "//'turbo.gammalib'" dir
  4. To drop .c suffixes before copying all files in UNIX directory dir to an existing PDS 'turbo.gammalib':
    cp -S d=.c dir/* "//'turbo.gammalib'"

Localization

cp uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_COLLATE
  • LC_CTYPE
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

Format of the TZ environment variable explains how to set the local time zone with the TZ environment variable.

Environment variables

cp uses the following environment variable when copying records to or from MVS data sets:
_EDC_ZERO_RECLEN
If set to Y before calling cp, an empty record (zero-length) is treated as a single newline character and is not ignored. Also, a single newline character is written to the file as an empty record, and a single blank will be represented by "  \n". If you do not set this environment variable when copying records, then the string "  \n is" copied the same way as the string "\n": both are read and written as "\n", where "\n" indicates that z/OS XL C/C++ will write a record containing a single blank to the file (the default behavior of z/OS XL C/C++). All other blanks in the output are read back as blanks, and any empty records are ignored.
cp also uses the following environment variable:
_UNIX03
For more information about the effect of _UNIX03 on this command, see Shell commands changed for UNIX03.

Exit values

0
Successful completion
1
Failure due to any of the following:
  • An argument had a trailing slash (/) but was not a directory.
  • Inability to find a file.
  • Inability to open an input file for reading.
  • Inability 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.
  • An unrecoverable error when using -r or -r. Possible unrecoverable -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 incorrect command-line option.
  • Too few arguments on the command line.
  • A target that should be a directory but isn't.
  • No space left on target device.
  • Insufficient memory to hold the data to be copied.
  • Inability to create a directory to hold a target file.

Messages

Possible error messages include:
cannot allocate target string
cp has no space to hold the name of the target file. Try to release 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). In this case, cp does nothing.
unreadable directory name
cp cannot read the specified directory; for example, because you do not have appropriate permission.

Portability

POSIX.2, X/Open Portability Guide, UNIX systems.

The -F and -m options are extensions of the POSIX standard.

Related information

cat, cpio, ln, mv, rm