cpioarchiver to copy and back up files |
Command |
SYNOPSIS DESCRIPTION Primary Options Secondary Options Handling Additional Attributes Restoring DACLs EXAMPLES ENVIRONMENT VARIABLES DIAGNOSTICS PORTABILITY WARNING NOTES AVAILABILITY SEE ALSO |
cpio-o[-aBcHhjNvyz] [-Cblocksize] [-Ofile] [-Vvolpat]
cpio-i[-BbcdfHhjmNrsStuvqy] [-Cblocksize] [-Ifile] [-Vvolpat] [pattern...]
cpio-p[-aBdlNmruv]directory
Thecpiocommand manipulates files calledcpioarchives. Acpioarchive is a concatenation of files and directories preceded by a header that gives the file name and other file system information. Withcpio, 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 ofcpiocan also save and restore additional Windows NT/2000/XP/2003/Vista/7/2008 attributes.
Whencpioadds 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.
The three forms of the command shown in the synopsis represent the main functions ofcpio. Every call tocpiomust specify one and only one of the following primary options:
reads an existing archive (created with the-ooption) from the standard input. Unless you specify the-toption,cpio-iextracts all files matching one or more of the givenpatternarguments from the archive. Patterns are the same as those used by file name generation (seesh). When you do not specify apatternargument, the default pattern*is used; as a result,cpioextracts all files.
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 thelsorfindcommands. For example,
ls . | cpio -o >arch
useslsto list the files of the current directory, then pipes this list as input tocpio. The resulting archive contains the contents of all the files, and is written toarch.
When you specify a compression option (-jor-z) with the-ooption and the specified archive is not compressed, an error message results and no files are extracted or table of contents displayed.
copies the list of files read from standard input to the specifieddirectory. You can use this option to copy entire file trees.
Consult the synopsis lines to determine which of the following additional options can be applied with a particular primary option:
resets the access time of each file that is accessed for copying to what it was before the copy took place.
uses buffers of 5120 bytes for input and output rather than the default 512 byte buffers.
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-sand-Soptions.
sets the buffer size to a specifiedblocksize, rather than the default 512 byte buffers.
reads and writes header information in ASCII form. Normally,cpiowrites 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.
forces the creation of necessary intermediate directories if they do not already exist.
inverts the sense of pattern matching. More precisely,cpioextracts a file from the archive if and only if it does not match any of thepatternarguments.
creates and readscpioarchives that contain extraneous header characters, for compatibility with historical versions ofcpio.
creates and readscpioarchives 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 MKScpiois "big-endian." For example, the 32-bit hexadecimal number1234, written as acpioheader using the-hoption, would be stored in "little-endian" order:
34 12
Without the-hoption,cpiodefaults to "big-endian" ordering:
12 34
MKScpioautomatically senses the byte ordering of any archive header being read, and prints a notification to standard output if byte reversal is present.
causes input to be read from the specifiedfile, rather than standard input. The specifiedfilemay be the name of a device, for example,A:.cpioreads the raw disk for thecpiofile.
uses thebzip2format to compress the archive being created. Normally, when you extract from a an archive compressed using this format,cpioautomatically detects thebzip2format and decompresses it appropriately.
Some versions of thecpioutility on other systems may not automatically detect and decompressbzip2-compressed archives. To extract files from these archives on such a system, you should first decompress the archive using thebunzip2utility.
gives permission to create a link to a file rather than making a separate copy.
resets the modification time of an output file to the modification time of the source file. Normally, whencpiocopies 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.
handles additional Windows NT/2000/XP/2003/Vista/7/2008 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 theTK_NTSECURITYINFO_OFFenvironment variable is set, because this environment variable disables the use of access control lists.
For full details on the behavior of-Nand the handling of the additional attributes, seeHandling Additional Attributes.
causes output to be written to the specifiedfile, rather than standard output. The specifiedfilemay be the name of a device, for example,A:, and writes thecpiofile to the raw disk.
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/ncharacters have/radded in front of them.
lets you rename files ascpioworks. When extracting,cpiodisplays 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,cpioprocesses the file or directory with no modification to the name. If you just press ENTER,cpioskips the file.
for portability reasons, swaps pairs of 16-bit words within long words only when extracting files. This option does not affect the headers.
for portability reasons, swaps pairs of bytes within each 16-bit word only when extracting files. This option does not affect the headers.
prevents file extraction, producing instead a table of file names contained in the archive. See the description of the-voption.
copies an archive file to a target file even if the target is newer than the archive. Normally,cpiodoes not copy the file.
provides automatic multi-volume support.cpiowrites output to files whose names are formatted usingvolpat. The current volume number replaces any occurrence of#involpat. When you invokecpiowith 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.cpioissues a similar message when a write error or read error occurs on the archive; the reasoning is that this kind of error means thatcpiohas reached the end of the volume and should go on to a new one.
provides more verbose information than usual.cpioprints the names of files as it extracts them from or adds them to archives. When you specify both-vand-t,cpioprints a table of files in a format similar to that produced by thels-lcommand.
when used with-V,-ydoes not ask for a volume number to begin with, but does ask ifcpiogets a read or write error.
performs compression. Output is at compression level 5. On input, any compression level up to 9 is acceptable. In addition,-zexpands compressed archives on input.
cpiouses the gzip format to compress files.
The byte and word swapping done by the-b,-S, and-soptions is effective only for the file data written. With or without the-coption, header information is always written in a machine-invariant format.
With the-Noption,cpiocan handle saving and restoring additional Windows NT/2000/XP/2003/Vista/7/2008 attributes. This option has no effect when theTK_NTSECURITYINFO_OFFenvironment variable is set.
The additional information for each file in the archive is stored in a file named.filename_MKS_ACL.kshwherefilenameis the name of the original file. This file (called aspecial file) is used to restore the additional attributes when the original file (called aregular file) is extracted. Archives containing special files are calledenhancedarchives.
When you use-Nwith-oto create a new archive, for each file being added to the archive,cpioalso adds the the corresponding special file. The special file has the same modification timestamp as the regular file and contains thechaclcommands to restore the regular file's discretionary access control list (DACL),chowncommands to set the owner and group information, and achmodcommand to set the compressed attribute if the regular file has that attribute set.
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 whencpio-oNis specified, that special file is ignored.
You can use-Nwith-ito extract files from an enhanced archive. For each regular file retrieved from the archive, the corresponding special file is also retrieved from the archive; the commands in this special file are then applied to the regular file and the special file is deleted (from the disk, but not from the archive).
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 thechownreference page.
When you use-iwithout-Non an enhanced archive,cpioextracts all files (both regular and special). Users with versions of MKS Toolkit that do not contain the-Nfeature ofcpiobut do contain thechaclcommand can still make use of the special files in an enhanced archive. Such users can extract all the files in the archive with-i, and then use thefindcommand to first execute the special files to restore the DACLs for the regular files and then delete those special files.
For information on how DACLs are restored, seeRestoring DACLs.
Using-itwith-Nto display the table of contents of an enhanced archive displays only the regular files in the archive, unless you also specify-v.cpio-itvNdisplays both regular and special files as doescpio-it.
Using the-Noption with-phas no effect.
Ifcpiois interrupted while restoring an enhanced archive using-N, special files (that is, files of the form.filename_MKS_ACL.kshmay be left behind. You can delete these files with no consequence.
When enhanced archives are created usingcpio-oN, the discretionary access control lists (DACLs) associated with file are preserved and these DACLs are restored when the files and directories are restored.
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 runcpio-oNin directorydir1, savingdir2andfile3. ACE2 is saved withdir2and ACE3 withfile3. Now restore thiscpioarchive todir4.
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 todir2, 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 underdir1,dir2would have different ACEs, since ACE1 would have been assigned todir2, and ignored the version of ACE1 associated withdir1. While users would have the same access as in the original case, the inheritance structure would be changed; in particular, dropping ACE1 fromdir1would 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, wheredir1may contain many files, all of which would need to be assigned ACE1).
Instead,cpiosimply saves ACE2 withdir2and ACE3 withfile3. If the files are restored todir1(or any directory with inheritable ACE1), access rules are identical for saved and restored files. However, ifdir2andfile3are instead restored todir4, with inheritable ACE4, the access rules are different.
This is right, though, in that the attributes have been retained for the files thatcpiosaved 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 ondir2andfile3be wide open. If a user did not have read access todir1but did todir4, restoring the archive todir4would give this user access to these files.
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 directoryxxthat may be larger than a single diskette, using compression:
find xx -type f | cpio -ocvzV a:#.cpz
Contains the format to be used bycpio,tar,pax,vpax,zip, orunzipwhen reading and writing file names to an archive. The value must be one ofASCII_ANSI,ASCII_OEM, orUTF-8(or their equivalents) as described in theFile Character Formatssection of theunicodereference 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.
If set, MKS Toolkit utilities do not use ASPI support if it is present and do not display warning messages if it is not.
MKS Toolkit supports hard links under Windows NT/2000/XP/2003/Vista/7/2008 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 variableTK_NTLINKS_OFFto disable this support.
MKS Toolkit supports Windows NT/2000/XP/2003/Vista/7/2008 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 variableTK_NTSECURITYINFO_OFFto disable this feature.
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,cpiostores 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 theTK_UNIX_FILESYSTEMenvironment variable. As long as this environment variable is either set when performing both backup and restore operations, or unset when performing both, usingcpioto backup and restore should work as expected.
For details on the Enhanced UNIX Compatibility Mode and the virtual file system, see theEUCMreference page.
Possible exit status values are:
Successful completion.
Failure due to any of the following:
x/OPEN Portability Guide 4.0. Windows 2000. Windows XP. Windows Server 2003. Windows Vista. Windows 7. Windows Server 2008. 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-aoption is only effective under the NTFS file system.
On Windows NT/2000/XP/2003/Vista/7/2008,cpiorecognizes 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 undertape. For example
/dev/mt0
has the same effect as specifying//./TAPE0, with the added advantage thatcpioautomatically senses and sets the correct block size of the tape.
The-Noption and the related handling of additional Windows NT/2000/XP/2003/Vista/7/2008 attributes are MKS extensions. However, the resultingcpioarchives are in standard format and can be read by standard implementations ofcpio.
The-b,-C,-I,-O,-q,-S,-s,-V,-y, and-zoptions are extensions to thex/OPEN standard.
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 driveA:for raw disk input, you first perform a command likelsordiron 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 MKS Toolkit command that you want to use.
When using its default binary method of storage,cpiocannot save files larger than two gigabytes in size in an archive. When storing archives in ASCII (because of-c),cpiocannot save files larger than eight gigabytes in size in an archive. However, other programs that extract files fromcpioarchives may be unable to properly extract files larger than two gigabytes andcpioissues a warning to that effect when you attempt to save such a file.
The-uoption ofcpiocalls thesortutility. To ensure that this option works correctly, you should make certain that the MKS Toolkitsortutility (or one compatible with it) is the first one located by the command search path.
MKS Toolkit for System Administrators
MKS Toolkit for Developers
MKS Toolkit for Interoperability
MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition
MKS Toolkit Backup and Tape Handling Solutions Guide
MKS Toolkit 9.3 Documentation Build 6.