cpio
--- The Detailed Node Listing ---
Invoking cpio
1 Introduction
GNU cpio copies files into or out of a cpio or tar archive, The archivecan be another file on the disk, a magnetic tape, or a pipe.
GNU cpio supports the following archive formats: binary, old ASCII, newASCII, crc, HPUX binary, HPUX old ASCII, old tar, and POSIX.1 tar. Thetar format is provided for compatibility with the tar program. Bydefault, cpio creates binary format archives, for compatibility witholder cpio programs. When extracting from archives, cpio automaticallyrecognizes which kind of archive it is reading and can read archivescreated on machines with a different byte-order.
2 Tutorial
GNU cpio performs three primary functions. Copying files to anarchive, Extracting files from an archive, and passing files to anotherdirectory tree. An archive can be a file on disk, one or more floppydisks, or one or more tapes.
When creating an archive, cpio takes the list of files to be processedfrom the standard input, and then sends the archive to the standardoutput, or to the device defined by the-F option. See Copy-out mode. Usually find or ls is used to provide this listto the standard input. In the following example you can see thepossibilities for archiving the contents of a single directory.
% ls | cpio -ov > directory.cpio |
The -o option creates the archive, and the-v optionprints the names of the files archived as they are added. Notice thatthe options can be put together after a single- or can be placedseparately on the command line. The ‘>’ redirects the cpio outputto the file ‘directory.cpio’.
If you wanted to archive an entire directory tree, the find command canprovide the file list to cpio:
% find . -print -depth | cpio -ov > tree.cpio |
This will take all the files in the current directory, the directoriesbelow and place them in the archive tree.cpio. Again the-ocreates an archive, and the -v option shows you the name of thefiles as they are archived. SeeCopy-out mode. Using the ‘.’ in thefind statement will give you more flexibility when doing restores, as itwill save file names with a relative path vice a hard wired, absolutepath. The-depth option forces ‘find’ to print of theentries in a directory before printing the directory itself. Thislimits the effects of restrictive directory permissions by printing thedirectory entries in a directory before the directory name itself.
Extracting an archive requires a bit more thought because cpio will notcreate directories by default. Another characteristic, is it will notoverwrite existing files unless you tell it to.
% cpio -iv < directory.cpio |
This will retrieve the files archived in the file directory.cpio andplace them in the present directory. The-i option extracts thearchive and the -v shows the file names as they are extracted. If you are dealing with an archived directory tree, you need to use the-d option to create directories as necessary, something like:
% cpio -idv < tree.cpio |
This will take the contents of the archive tree.cpio and extract it tothe current directory. If you try to extract the files on top of filesof the same name that already exist (and have the same or latermodification time) cpio will not extract the file unless told to do soby the -u option. See Copy-in mode.
In copy-pass mode, cpio copies files from one directory tree to another,combining the copy-out and copy-in steps without actually using anarchive. It reads the list of files to copy from the standard input;the directory into which it will copy them is given as a non-optionargument. See Copy-pass mode.
% find . -depth -print0 | cpio --null -pvd new-dir |
The example shows copying the files of the present directory, andsub-directories to a new directory called new-dir. Some new options arethe-print0 available with GNU find, combined with the--null option of cpio. These two options act together to sendfile names between find and cpio, even if special characters areembedded in the file names. Another is -p, which tells cpio topass the files it finds to the directory ‘new-dir’.
3 Invoking cpio
3.1 Copy-out mode
In copy-out mode, cpio copies files into an archive. It reads a listof filenames, one per line, on the standard input, and writes thearchive onto the standard output. A typical way to generate the listof filenames is with the find command; you should give find the -depthoption to minimize problems with permissions on directories that areunreadable. SeeOptions.
cpio {-o|--create} [-0acvABLV] [-C bytes] [-H format] [-M message] [-O [[user@]host:]archive] [-F [[user@]host:]archive] [--file=[[user@]host:]archive] [--format=format] [--message=message] [--null] [--reset-access-time] [--verbose] [--dot] [--append] [--block-size=blocks] [--dereference] [--io-size=bytes] [--rsh-command=command] [--help] [--version] < name-list [> archive]
3.2 Copy-in mode
In copy-in mode, cpio copies files out of an archive or lists thearchive contents. It reads the archive from the standard input. Anynon-option command line arguments are shell globbing patterns; onlyfiles in the archive whose names match one or more of those patterns arecopied from the archive. Unlike in the shell, an initial ‘.’ in afilename does match a wildcard at the start of a pattern, and a ‘/’ in afilename can match wildcards. If no patterns are given, all files areextracted. See Options.
cpio {-i|--extract} [-bcdfmnrtsuvBSV] [-C bytes] [-E file] [-H format] [-M message] [-R [user][:.][group]] [-I [[user@]host:]archive] [-F [[user@]host:]archive] [--file=[[user@]host:]archive] [--make-directories] [--nonmatching] [--preserve-modification-time] [--numeric-uid-gid] [--rename] [--list] [--swap-bytes] [--swap] [--dot] [--unconditional] [--verbose] [--block-size=blocks] [--swap-halfwords] [--io-size=bytes] [--pattern-file=file] [--format=format] [--owner=[user][:.][group]] [--no-preserve-owner] [--message=message] [--help] [--version] [--no-absolute-filenames] [--sparse] [-only-verify-crc] [--to-stdout] [-quiet] [--rsh-command=command] [pattern...] [< archive]
3.3 Copy-pass mode
In copy-pass mode, cpio copies files from one directory tree toanother, combining the copy-out and copy-in steps without actuallyusing an archive. It reads the list of files to copy from thestandard input; the directory into which it will copy them is given asa non-option argument. See Options.
cpio {-p|--pass-through} [-0adlmuvLV] [-R [user][:.][group]] [--null] [--reset-access-time] [--make-directories] [--link] [--preserve-modification-time] [--unconditional] [--verbose] [--dot] [--dereference] [--owner=[user][:.][group]] [--sparse] [--no-preserve-owner] [--help] [--version] destination-directory < name-list
3.4 Options
-
Read a list of filenames terminated by a null character, instead of anewline, so that files whose names contain newlines can be archived. GNU find is one way to produce a list of null-terminated filenames. This option may be used in copy-out and copy-pass modes.
-
Reset the access times of files after reading them, sothat it does not look like they have just been read.
-
Append to an existing archive. Only works in copy-outmode. The archive must be a disk file specified withthe
-O or
-F (
--file) option.
-
Swap both halfwords of words and bytes of halfwords in the data. Equivalent to -sS. This option may be used in copy-in mode. Use thisoption to convert 32-bit integers between big-endian and little-endianmachines.
-
Set the I/O block size to 5120 bytes. Initially theblock size is 512 bytes.
-
Set the I/O block size to
block-size * 512 bytes.
-
Use the old portable (ASCII) archive format.
-
Set the I/O block size to
io-size bytes.
-
Create leading directories where needed.
-
Read additional patterns specifying filenames to extract or list from
file. The lines of
file are treated as if they had been non-optionarguments to cpio. This option is used in copy-in mode,
-
Only copy files that do not match any of the givenpatterns.
-
Archive filename to use instead of standard input or output. To use atape drive on another machine as the archive, use a filename that startswith ‘
hostname:’, where
hostname is the name or IPaddress of the machine. The hostname can be preceded by a username and an‘
@’ to access the remote tape drive as that user, if you havepermission to do so (typically an entry in that user's
~/.rhostsfile).
-
With
-F,
-I, or
-O, take the archive file name to be alocal file even if it contains a colon, which wouldordinarily indicate a remote host name.
-
Use archive format
format. The valid formats are listed belowwith file size limits for individual files in parentheses; the samenames are also recognized in all-caps. The default in copy-in mode isto automatically detect the archive format, and in copy-out mode is‘
bin’.
-
‘
bin’
-
The obsolete binary format. (2147483647 bytes)
‘
odc’
-
The old (POSIX.1) portable format. (8589934591 bytes)
‘
newc’
-
The new (SVR4) portable format, which supports file systems having morethan 65536 i-nodes. (4294967295 bytes)
‘
crc’
-
The new (SVR4) portable format with a checksum added.
‘
tar’
-
The old tar format. (8589934591 bytes)
‘
ustar’
-
The POSIX.1 tar format. Also recognizes GNU tar archives, which aresimilar but not identical. (8589934591 bytes)
‘
hpbin’
-
The obsolete binary format used by HPUX's cpio (which stores devicefiles differently).
‘
hpodc’
- The portable format used by HPUX's cpio (which stores device filesdifferently).
-
The obsolete binary format. (2147483647 bytes)
-
Run in copy-in mode. See
Copy-in mode.
-
Archive filename to use instead of standard input. To use a tape driveon another machine as the archive, use a filename that starts with‘
hostname:’, where
hostname is the name or IP addressof the remote host. The hostname can be preceded by a username and an ‘
@’ toaccess the remote tape drive as that user, if you have permission to doso (typically an entry in that user's
~/.rhosts file).
-
Ignored; for compatibility with other versions of cpio.
-
Link files instead of copying them, when possible.
-
Copy the file that a symbolic link points to, rather than the symboliclink itself.
-
Retain previous file modification times when creating files.
-
Print
message when the end of a volume of the backup media (such as atape or a floppy disk) is reached, to prompt the user to insert a newvolume. If
message contains the string ‘
%d’, it is replaced by thecurrent volume number (starting at 1).
-
Show numeric UID and GID instead of translating them into names when using the
--verbose option.
-
Create all files relative to the current directory in copy-in mode, evenif they have an absolute file name in the archive.
-
Do not change the ownership of the files; leave them owned by the userextracting them. This is the default for non-root users, so that userson System V don't inadvertantly give away files. This option can beused in copy-in mode and copy-pass mode
-
Run in copy-out mode. See
Copy-out mode.
-
Archive filename to use instead of standard output. To use a tape driveon another machine as the archive, use a filename that starts with‘
hostname:’, where
hostname is the name or IP addressof the machine. The hostname can be preceded by a username and an ‘
@’ toaccess the remote tape drive as that user, if you have permission to doso (typically an entry in that user's
~/.rhosts file).
-
Verify the CRC's of each file in the archive, when reading a CRC formatarchive. Don't actually extract the files.
-
Run in copy-pass mode. See
Copy-pass mode.
-
Do not print the number of blocks copied.
-
Interactively rename files.
-
In copy-in and copy-pass mode, set the ownership of all files createdto the specified
owner (this operation is allowed only for thesuper-user). In copy-out mode, store the supplied owner information inthe archive.
The argument can be either the user name or the user nameand group name, separated by a dot or a colon, or the group name,preceeded by a dot or a colon, as shown in the examples below:
cpio --owner smith cpio --owner smith: cpio --owner smith:users cpio --owner :users
If the group is omitted but the ‘:’ or ‘.’ separator isgiven, as in the second example. the given user's login group will beused.
-
Notifies cpio that is should use
command to communicate with remotedevices.
-
Swap the bytes of each halfword (pair of bytes) in the files. This optioncan be used in copy-in mode.
-
Swap the halfwords of each word (4 bytes) in the files. This option maybe used in copy-in mode.
-
Write files with large blocks of zeros as sparse files. This option isused in copy-in and copy-pass modes.
-
Print a table of contents of the input.
-
Extract files to standard output. This option may be used in copy-in mode.
-
Replace all files, without asking whether to replaceexisting newer files with older files.
-
List the files processed, or with
-t, give an ‘
ls -l’ styletable of contents listing. In a verbose table of contents of a ustararchive, user and group names in the archive that do not exist on thelocal system are replaced by the names that correspond locally to thenumeric UID and GID stored in the archive.
-
Print a ‘
.’ for each file processed.
- Print the cpio program version number and exit.
-0
--null
-a
--reset-access-time
-A
--append
-b
--swap
-B
--block-size=
block-size
-c
-C
io-size
--io-size=
io-size
-d
--make-directories
-E
file
--pattern-file=
file
-f
--nonmatching
-F
archive
--file=
archive
--force-local
-H
format
--format=
format
-i
--extract
-I
archive
-k
-l
--link
-L
--dereference
-m
--preserve-modification-time
-M
message
--message=
message
-n
--numeric-uid-gid
--no-absolute-filenames
--no-preserve-owner
-o
--create
-O
archive
--only-verify-crc
-p
--pass-through
--quiet
-r
--rename
-R
owner
--owner
owner
--rsh-command=
command
-s
--swap-bytes
-S
--swap-halfwords
--sparse
-t
--list
--to-stdout
-u
--unconditional
-v
--verbose
-V
--dot
--version
4 Magnetic Media
Archives are usually written on removable media–tape cartridges, magtapes, or floppy disks.
The amount of data a tape or disk holds depends not only on its size,but also on how it is formatted. A 2400 foot long reel of mag tapeholds 40 megabytes of data when formated at 1600 bits per inch. Thephysically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
Magnetic media are re-usable–once the archive on a tape is no longerneeded, the archive can be erased and the tape or disk used over. Mediaquality does deteriorate with use, however. Most tapes or disks shouldbe disgarded when they begin to produce data errors.
Magnetic media are written and erased using magnetic fields, and shouldbe protected from such fields to avoid damage to stored data. Stickinga floppy disk to a filing cabinet using a magnet is probably not a goodidea.
5 Reporting bugs or suggestions
It is possible you will encounter a bug in cpio. If this happens, we would like to hear about it. As the purpose of bugreporting is to improve software, please be sure to include maximuminformation when reporting a bug. The information needed is:
- Version of the package you are using.
- Compilation options used when configuring the package.
- Conditions under which the bug appears.
Send your report to <bug-cpio@gnu.org>. Allow us a couple ofdays to answer.