SYNOPSIS
cpio
cpio
cpio
DESCRIPTION
The cpio command manipulates files called cpio archives. A cpio archive is a concatenation of files and directories preceded by a header that gives the file name and other file system information. With cpio, you can create a new archive, extract the contents of an existing archive, list archive contents, and copy files from one directory to another.
The MKS version of cpio can also save and restore additional 8.1/2012R2/10/2016/2019/11/2022 attributes.
When cpio adds a sparse file to an archive, it stores it as a non-sparse file but also stores the sparse attribute. When a file with a sparse attribute is extracted on a NTFS file system (which supports sparse files), the file is extracted as a sparse file. On other file sytems, a warning is given and it is extracted as a non-sparse file. Sparse archive files are never created because most tapes, floppy disks, and other archiving media cannot understand them. It is recommended that you compress any archive which contain files with the sparse attribute set to keep the size of the archive reasonable.
Primary Options
The three forms of the command shown in the synopsis represent the main functions of cpio. Every call to cpio must specify one and only one of the following primary options:
-i -
reads an existing archive (created with the
-o option) from the standard input. Unless you specify the-t option, cpio-i extracts all files matching one or more of the given pattern arguments from the archive. Patterns are the same as those used by file name generation (see sh). When you do not specify a pattern argument, the default pattern * is used; as a result, cpio extracts all files. -o -
writes a new archive to the standard output, using the list of files read from the standard input. Such a list might be produced by the ls or find commands. For example,
ls . | cpio -o >arch
uses ls to list the files of the current directory, then pipes this list as input to cpio. The resulting archive contains the contents of all the files, and is written to arch.
- Note:
-
When you specify a compression option (
-j or-z ) with the-o option and the specified archive is not compressed, an error message results and no files are extracted or table of contents displayed.
-p -
copies the list of files read from standard input to the specified directory. You can use this option to copy entire file trees.
Secondary Options
Consult the synopsis lines to determine which of the following additional options can be applied with a particular primary option:
-a -
resets the access time of each file that is accessed for copying to what it was before the copy took place.
-B -
uses buffers of 5120 bytes for input and output rather than the default 512 byte buffers.
-b -
causes 16-bit words to be swapped within each long word and bytes to be swapped within each 16-bit word of each extracted file. This facilitates the transfer of information between different CPU architectures. This is equivalent to specifying both the
-s and-S options. -C blocksize-
sets the buffer size to a specified blocksize, rather than the default 512 byte buffers.
-c -
reads and writes header information in ASCII form. Normally, cpio writes the header information in a compact binary format. This option produces an archive more amenable to transfer through non-binary streams (such as some data communications links) and is highly recommended for moving data between different processors, such as between a UNIX system and a PC.
-d -
forces the creation of necessary intermediate directories if they do not already exist.
-f -
inverts the sense of pattern matching. More precisely, cpio extracts a file from the archive if and only if it does not match any of the pattern arguments.
-H -
creates and reads cpio archives that contain extraneous header characters, for compatibility with historical versions of cpio.
-h -
creates and reads cpio archives with headers structured in a "little-endian" pattern. The term "little-endian" refers to the internal ordering of bytes representing numbers, stipulating that the least significant values come first. This is the common standard for PCs, but is contrary to the "big-endian" standard of most UNIX machines.
The default for MKS cpio is "big-endian." For example, the 32-bit hexadecimal number 1234, written as a cpio header using the
-h option, would be stored in "little-endian" order:34 12
Without the
-h option, cpio defaults to "big-endian" ordering:12 34
MKS cpio automatically senses the byte ordering of any archive header being read, and prints a notification to standard output if byte reversal is present.
-I file-
causes input to be read from the specified file, rather than standard input. The specified file may be the name of a device, for example, A:. cpio reads the raw disk for the cpio file.
-j -
uses the bzip2 format to compress the archive being created. Normally, when you extract from a an archive compressed using this format, cpio automatically detects the bzip2 format and decompresses it appropriately.
-l -
gives permission to create a link to a file rather than making a separate copy.
-m -
resets the modification time of an output file to the modification time of the source file. Normally, when cpio copies data into a file, it sets the modification time of the file to the time when the file is written. This option has no effect on directories.
-N -
handles additional 8.1/2012R2/10/2016/2019/11/2022 attributes for each file in the archive. For each file in the archive, these additional attributes are stored in a file .filename_MKS_ACL.ksh (note the leading dot). This option has no effect when the TK_NTSECURITYINFO_OFF environment variable is set, because this environment variable disables the use of access control lists.
For full details on the behavior of
-N and the handling of the additional attributes, see Handling Additional Attributes. -O file-
causes output to be written to the specified file, rather than standard output. The specified file may be the name of a device, for example, A:, and writes the cpio file to the raw disk.
-q -
assumes all created files are ASCII text. On UNIX and POSIX-compliant systems, this means that any \r (carriage return) characters are stripped, and only the \n (newlines) are retained. On Windows systems, all \n characters have \r added in front of them.
-r -
lets you rename files as cpio works. When extracting, cpio displays the name of the component it is about to extract and gives you the chance to specify a name for the extracted file. If you enter . as the name, cpio processes the file or directory with no modification to the name. If you just press ENTER, cpio skips the file.
-S -
for portability reasons, swaps pairs of 16-bit words within long words only when extracting files. This option does not affect the headers.
-s -
for portability reasons, swaps pairs of bytes within each 16-bit word only when extracting files. This option does not affect the headers.
-t -
prevents file extraction, producing instead a table of file names contained in the archive. See the description of the
-v option. -u -
copies an archive file to a target file even if the target is newer than the archive. Normally, cpio does not copy the file.
-V volpat-
provides automatic multi-volume support. cpio writes output to files whose names are formatted using volpat. The current volume number replaces any occurrence of # in volpat. When you invoke cpio with this option, it asks for the first number in the archive set, and waits for you to press ENTER before it proceeds with the operation. cpio issues a similar message when a write error or read error occurs on the archive; the reasoning is that this kind of error means that cpio has reached the end of the volume and should go on to a new one.
-v -
provides more verbose information than usual. cpio prints the names of files as it extracts them from or adds them to archives. When you specify both
-v and-t , cpio prints a table of files in a format similar to that produced by the ls-l command. -y -
when used with
-V ,-y does not ask for a volume number to begin with, but does ask if cpio gets a read or write error. -z -
performs compression. Output is at compression level 5. On input, any compression level up to 9 is acceptable. In addition,
-z expands compressed archives on input.cpio uses the gzip format to compress files.
The byte and word swapping done by the
Handling Additional Attributes
With the
The additional information for each file in the archive is stored in a file named .filename_MKS_ACL.ksh where filename is the name of the original file. This file (called a special file) is used to restore the additional attributes when the original file (called a regular file) is extracted. Archives containing special files are called enhanced archives.
When you use
- Note:
-
Special files are created as temporary files and then added to the archive with the appropriate name. As a result, if a special file already exists when cpio
-oN is specified, that special file is ignored.
You can use
- Note:
-
To properly restore the ownership and group information for files being extracted from an enhanced archive, you must have the appropriate permissions as outlined in the chown reference page.
When you use
For information on how DACLs are restored, see Restoring DACLs.
Using
Using the
- Note:
-
If cpio is interrupted while restoring an enhanced archive using
-N , special files (that is, files of the form .filename_MKS_ACL.ksh may be left behind. You can delete these files with no consequence.
Restoring DACLs
When enhanced archives are created using cpio
However, the access controls may still be different on restoration than for the original file, if files are retrieved to a location with different inheritable access control entries (ACEs) than the original location. ACEs can either be assigned explicitly to a given file or can be inherited from a higher directory. Access to a file depends both on the ACEs associated directly with that file, and on the ACEs inherited from above.
Consider the following hierarchy, with ACEs assigned to files and directories. No two ACEs in this example apply to the same user.
dir1 (ACE1) dir4 (ACE4) | dir2 (ACE2) | file3 (ACE3)
Let ACE1 and ACE2 be inherited. Now run cpio
To guarantee that all users have exactly the same access to restored files, no matter where they were restored in a directory tree, would require that all inheritance in the destination tree be overridden and that all inheritances in the source directory tree be expanded. In this example, it would require that ACE1 be assigned to dir2, and that ACE4 be ignored.
But this does not preserve the inheritance structure cleanly; restored files do not have the same ACEs that the original files did. Even if these files were restored to their original location under dir1, dir2 would have different ACEs, since ACE1 would have been assigned to dir2, and ignored the version of ACE1 associated with dir1. While users would have the same access as in the original case, the inheritance structure would be changed; in particular, dropping ACE1 from dir1 would have no effect in the restored setting, while it obviously would have in the original setting (and this gets far sloppier in a real example, where dir1 may contain many files, all of which would need to be assigned ACE1).
Instead, cpio simply saves ACE2 with dir2 and ACE3 with file3. If the files are restored to dir1 (or any directory with inheritable ACE1), access rules are identical for saved and restored files. However, if dir2 and file3 are instead restored to dir4, with inheritable ACE4, the access rules are different.
This is right, though, in that the attributes have been retained for the files that cpio saved and restored. Consider an analogy, where files are saved from a read-only file system (for example, a write-protected floppy disk), and restored to a read-write file system, such as the main hard drive. Here it seems clear that each file should be restored with its original permissions (which may well allow writing) instead of with read-only permission, based on an attribute that was set higher in the directory structure. Similarly, let the permissions on dir2 and file3 be wide open. If a user did not have read access to dir1 but did to dir4, restoring the archive to dir4 would give this user access to these files.
EXAMPLES
To copy an entire diskette file system to the current directory, use
find a: -type f | cpio -pvd .
To archive the current directory onto diskette in a system-independent (portable) format:
find . -type f | cpio -ocO a:
To recover a directory from a portable archive diskette:
cpio -icdm -I a:
To archive a directory xx that may be larger than a single diskette, using compression:
find xx -type f | cpio -ocvzV a:#.cpz
ENVIRONMENT VARIABLES
- TK_ARCHIVE_CHARSET
-
Contains the format to be used by cpio, tar, pax, vpax, zip, or unzip when reading and writing file names to an archive. The value must be one of ASCII_ANSI, ASCII_OEM, or UTF-8 (or their equivalents) as described in the File Character Formats section of the unicode reference page.
When this variable is unset or it is set to a value other than those listed earlier, the default OEM character set is used.
- TK_ASPI_SUPPORT_OFF
-
If set, MKS Toolkit utilities do not use ASPI support if it is present and do not display warning messages if it is not.
- TK_NTLINKS_OFF
-
MKS Toolkit supports hard links under 8.1/2012R2/10/2016/2019/11/2022 on NTFS file systems. There is a slight loss of performance for this support. If you do not require hard link support, you should set and export the environment variable TK_NTLINKS_OFF to disable this support.
- TK_NTSECURITYINFO_OFF
-
MKS Toolkit supports 8.1/2012R2/10/2016/2019/11/2022 security information on NTFS file systems. There is a slight loss of performance for this support. If you do not require any security information, you should set and export the environment variable TK_NTSECURITYINFO_OFF to disable this feature.
- TK_UNIX_FILESYSTEM
-
When this variable is set, the Enhanced UNIX Compatibility Mode is on and the virtual file system is in use.
When the Enhanced UNIX Compatibility Mode is on, cpio stores all path names in an archive as virtual file system path names. This ensures that when such files are extracted on a system that uses a single-rooted file system similar to virtual file system (such as UNIX or Linux), they are put in the correct location. If you don't want virtual file system path names stored in the archives you create, turn off the Enhanced UNIX Compatibility Mode by unsetting the TK_UNIX_FILESYSTEM environment variable. As long as this environment variable is either set when performing both backup and restore operations, or unset when performing both, using cpio to backup and restore should work as expected.
For details on the Enhanced UNIX Compatibility Mode and the virtual file system, see the EUCM reference page.
DIAGNOSTICS
Possible exit status values are:
PORTABILITY
x/OPEN Portability Guide 4.0. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022. All non-Berkeley UNIX systems after Version 7.
Some of the file attributes, such as owner, I-number, and so on, have degenerate values on some Windows file systems, because the file attributes have no real counterparts in the file system structure.
The
On 8.1/2012R2/10/2016/2019/11/2022, cpio recognizes device names only if you apply the prefix //./ to every device reference, as follows:
//./TAPE0 instead of TAPE0
We strongly recommend, however, that you specify tape devices as described under tape. For example
/dev/mt0
has the same effect as specifying //./TAPE0, with the added advantage that cpio automatically senses and sets the correct block size of the tape.
The
The
WARNING
Before performing a raw disk input/output operation on a given disk, you must first read a properly formatted disk of the same size in the same drive. For example, if you want to use a 1.44MB disk in drive A: for raw disk input, you first perform a command like ls or dir on a different, properly formatted 1.44 MB disk in that drive. Once this is done, place the disk that you want to use for raw disk input/output in the appropriate drive and issue the PTC MKS Toolkit command that you want to use.
NOTES
When using its default binary method of storage, cpio
cannot save files larger than two gigabytes in size in an archive.
When storing archives in ASCII (because of
The
AVAILABILITY
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
SEE ALSO
MKS Toolkit Backup and Tape Handling Solutions Guide
PTC MKS Toolkit 10.4 Documentation Build 39.