Where allowed to run: All environments (*ALL) Threadsafe: No |
Parameters Examples Error messages |
The Copy Object (COPY) command copies a single object or a group of objects.
By default, if the target object already exists, the copy of that individual object will fail. If the REPLACE(*YES) parameter is specified the target object is overwritten. The newly created object must be renamed if it is stored in the same directory as the original object. If it is stored in a directory other than the one that contains the original object, it can retain the name of the original object.
An object name pattern can be used to copy a group of related objects. A pattern cannot be used to copy a group of objects from one file system to another unless the names in the source meet the requirements of the target file system. For example, a file named /OBJA in QOpenSys cannot be copied to directory /QSYS.LIB/MYLIB.LIB/FILEA.FILE, because the QSYS.LIB file system requires a name in the form OBJA.MBR when writing to a file. All names found within the pattern would fail if they did not meet the requirement of name.object-type.
The copy command can also be used to copy a directory tree where the directory, its contents, and the contents of all of its subdirectories are copied. A subtree copy will attempt to preserve as many attributes from the original objects as possible. This would make it possible to migrate data from one file system to another.
If the original object is a read-only file (a file that has the PC read-only attribute flag turned on), and SUBTREE(*NODIR) is specified, the newly created object will not be read-only. This follows the conventions of the OS/2 hierarchical file system (HFS).
Note: When the value of the Directory subtree (SUBTREE) parameter is *NONE or *ALL, the PC read-only attribute flag will be copied. The subtree copy is intended to preserve as many attributes of the original objects as possible.
When the To directory (TODIR) parameter is specified, the object is copied to that directory with the same name. The copied object is authorized the same as the original object. The user who issues the command owns the copied object if the Owner (OWNER) parameter value is *NEW.
When copying a file with SUBTREE(*NODIR) specified to the "root" (/), QOpenSys, QDLS, and UDFS file systems, the Last access date/time and the Data change date/time are preserved in the new file, and the Attribute change date/time is updated to the current time. The Last access date/time of the original file is updated to the current time. In the case of copying to a database file member (*MBR) in the QSYS.LIB or independent ASP QSYS.LIB file systems, the Data change date/time is updated as well.
Note: If the parameter SUBTREE(*YES) is specified the Create date/time is updated as well.
This command is an alias for the Copy Object (CPY) command and can also be issued using the following alternative command name:
In addition to the COPY command, the Copy To Stream File (CPYTOSTMF) and Copy From Stream File (CPYFRMSTMF) commands can be used to copy between stream files and database member files or save files.
For more information about integrated file system commands, see the Integrated file system information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter.
Restrictions:
Note: The authority requirements for this command are complex with respect to file systems, object types, requested operations etc.. Therefore, see the iSeries Security Reference, SC41-5302 book for information about the required authorities for this command.
QSYS.LIB and independent ASP QSYS.LIB File System Differences
QOPT File System Differences
QNetWare File System Differences
QFileSvr.400 File System Differences
Network File System (NFS) Differences
Top |
Keyword | Description | Choices | Notes |
---|---|---|---|
OBJ | Object | Path name | Required, Positional 1 |
TODIR | To directory | Path name, '.' | Optional, Positional 2 |
TOOBJ | To object | Path name | Optional |
SYMLNK | Symbolic link | *NO, *YES | Optional |
FROMCCSID | From CCSID | 1-65533, *OBJ, *PCASCII, *JOBCCSID | Optional |
TOCCSID | To CCSID | 1-65533, *OBJ, *CALC, *STDASCII, *PCASCII, *JOBCCSID | Optional |
DTAFMT | Data Format | *BINARY, *TEXT | Optional |
SUBTREE | Directory subtree | *NODIR, *NONE, *ALL | Optional |
REPLACE | Replace object | *NO, *YES | Optional |
OWNER | Owner | *NEW, *KEEP | Optional |
FROMCODPAG | From Code Page | 1-32767, *OBJ, *PCASCII | Optional |
TOCODEPAGE | To Code Page | 1-32767, *OBJ, *CALC, *STDASCII, *PCASCII | Optional |
Top |
Specifies the path name of the object or a pattern to match the name of the object to be copied.
The object path name can be either a simple name or a name that is qualified with the name of the directory in which the object is located. A pattern can be specified in the last part of the path name. An asterisk (*) matches any number of characters and a question mark (?) matches a single character. If the path name is qualified or contains a pattern, it must be enclosed in apostrophes.
For more information on specifying path names, refer to "Object naming rules" in the CL concepts and reference topic in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter.
Note: An object name pattern can be used to copy multiple objects only when the To directory (TODIR) parameter is specified.
Top |
Specifies the path name of the directory to copy the object into. When this parameter is used, the copied object has the same name as the Object (OBJ) parameter specified.
For more information on specifying path names, refer to "Object naming rules" in the CL concepts and reference topic in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter.
Top |
Specifies the path name of the copied object. This is the name of the new object, including the path or relative path.
For more information on specifying path names, refer to "Object naming rules" in the CL concepts and reference topic in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter.
Top |
Specifies whether to copy the object or a symbolic link to the object.
Note: If a symbolic link is encountered during the copy of a subtree, the object it points to is copied. If the symbolic link points to a directory, the directory is copied but its contents are not. This is true even when the top-level directory of the directory tree is actually a symbolic link to a directory.
Top |
Specifies the method for obtaining the coded character set identifier (CCSID) for the source of the copy operation. This CCSID will be used for data conversion, if requested. This parameter is ignored if the object specified on the Object (OBJ) parameter is not a regular file. A regular file is a file that supports the integrated file system input/output (I/O) operations open, read, and write.
Top |
Specifies the data coded character set identifier (CCSID) for the target of the copy operation. This parameter is ignored if the object specified on the Object (OBJ) parameter is not a regular file. A regular file is a file that supports the integrated file system input/output (I/O) operations open, read, and write.
Top |
Specifies the format of the data in the file to be copied.
Do not convert data on the copy. However, if the object to be copied to has a different CCSID than the source object, all extended attributes will be converted into the CCSID of the new object before being set.
If a database member is to be copied to a stream file, any line-formatting characters (such as carriage return, tab, and end-of-file) are just converted from one CCSID to another.
If a stream file is to be copied to a database member, the stream file must contain end-of-line characters or the copy will fail. If the stream file does contain end-of-line characters, the following actions are performed during the copy to a database file.
Top |
Specifies whether or not to copy a directory subtree if the object specified by Object (OBJ) is a directory.
Pattern matching on the OBJ parameter only applies to the first level object. If the first level object is a directory, the pattern matching does not apply to its contents or the contents of its subdirectories.
If SUBTREE(*ALL) is specified, individual completion messages for each object are not issued. A final message is issued to indicate how many copies succeeded and how many failed. If objects did fail to copy, the command will issue a diagnostic message for each copy that failed.
There are a few differences in how attributes are copied when SUBTREE(*NONE) or SUBTREE(*ALL) is specified instead of the default SUBTREE(*NODIR). A directory subtree copy preserves as much of the original objects' attributes as possible.
Note: The copy will fail if the target object is a subdirectory of the source object, or if the target object matches the source object.
Top |
Specifies whether the target object is replaced if it already exists.
Top |
Specifies the owner of the newly created object.
Some file systems do not support changing the owner of certain object types. For example, the owner of *MBR objects in the QSYS.LIB and independent ASP QSYS.LIB file systems will be determined by the owner of the *FILE object that they are copied into.
Top |
Specifies the method for obtaining the code page for source of the copy operation. This code page will be used for data conversion, if requested. This parameter is ignored if the object specified on the Object (OBJ) parameter is not a regular file. A regular file is a file that supports the integrated file system input/output (I/O) operations open, read, and write.
Note: This parameter is replaced by From CCSID (FROMCCSID) but the FROMCODPAG parameter can still be used. However, because this parameter may be removed in a later release, whenever possible use the FROMCCSID parameter.
Top |
Specifies the data code page for the target of the copy operation. This parameter is ignored if the object specified on the Object (OBJ) parameter is not a regular file. A regular file is a file that supports the integrated file system input/output (I/O) operations open, read, and write.
Note: This parameter is replaced by To CCSID (TOCCSID) but the TOCODEPAGE parameter can still be used. However, because this parameter may be removed in a later release, whenever possible use the TOCCSID parameter.
Top |
The alternative command name for COPY is CPY. The following examples use the alternative command name, but COPY can be replaced directly for CPY in all of them.
Example 1: Copying a File
CPY OBJ('DECEMBER-1994-MONTHLY-PAYROLL-FILE') TOOBJ('PAY')
This command creates another file named PAY that is a duplicate of the file named DECEMBER-1994-MONTHLY-PAYROLL-FILE.
Example 2: Copying a File to Another Directory
CPY OBJ('PAY') TODIR('MYDIR')
This command creates another file named PAY in directory MYDIR.
Example 3: Copying a Symbolic Link
CPY OBJ('SL1') TOOBJ('YOURDIR/SL2') SYMLNK(*YES)
If SL1 is a symbolic link, the new object YOURDIR/SL2 is also a symbolic link. If SYMLNK(*NO) was specified, the new object would be a copy of whatever SL1 pointed to, as long as it was a legal candidate for the copy function.
Example 4: Copying with Conversion
CPY OBJ('/DATAFB') TOOBJ('/QSYS.LIB/APP1.LIB/DATA.FILE/DATAFB.MBR') TOCCSID(*CALC) DTAFMT(*TEXT)
This command copies stream file 'DATAFB' to the database file 'DATAFB.MBR'. By specifying TOCCSID(*CALC), the file system being copied to (the QSYS.LIB file system in this case) will try to create the new member in the same coded character set identifier (CCSID) as '/DATAFB'. If this fails (in this case, if 'DATA.FILE is not in the same CCSID as 'DATAFB'), the file system will be allowed to choose an appropriate CCSID and complete the copy. By specifying DTAFMT(*TEXT), the data in 'DATAFB' is handled as text and is converted into the CCSID chosen for the new file 'DATAFB.MBR'.
Example 5: Copying a Directory Subtree
CPY OBJ('/QDLS/MYINFO') TODIR('/myfolder') SUBTREE(*ALL) OWNER(*KEEP) REPLACE(*YES)
The *FLR object (QDLS file system folder) is created in the '/myfolder' directory in the "root" (/) file system with the path name '/myfolder/MYINFO'. Its contents are copied as well. Since OWNER(*KEEP) is specified, the new objects created will belong to the same profiles as the old objects. With the REPLACE parameter set to *YES if any of the target files already exist they will be overwritten.
Top |
*ESCAPE Messages
Top |