Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cpio VS tar and cp

Tags:

bash

cp

archive

tar

I just learned that cpio has three modes: copy-out, copy-in and pass-through.

I was wondering what are the advantages and disadvantages of cpio under copy-out and copy-in modes over tar. When is it better to use cpio and when to use tar?

Similar question for cpio under pass-through mode versus cp.

Thanks and regards!

like image 632
Tim Avatar asked Jun 03 '10 13:06

Tim


People also ask

Why use cpio instead of tar?

tar is able to search directories on its own and takes the list of files or directories to be backed up from command line arguments. cpio archives only the files or directories it is told to, but does not search subdirectories recursively on it's own.

What is cpio used for?

Description. GNU cpio is a tool for creating and extracting archives, or copying files from one place to another. It handles many cpio formats and reading and writing tar files. The following archive formats are supported: binary, old ASCII, new ASCII, CRC, HP-UX binary, HP-UX old ASCII, old tar, and POSIX.

Is cpio compressed?

cpio was originally designed to store backup file archives on a tape device in a sequential, contiguous manner. It does not compress any content, but resulting archives are often compressed using gzip or other external compressors.

What are tar files?

Tar (for Tape ARchive) is a UNIX command that creates a single file called an archive from a number of specified files or extracts (separates) the files from such an archive. A tar archive has the file suffix . tar. The files in a tar archive are not compressed, just gathered together in one file.


1 Answers

I see no reason to use cpio for any reason other than ripping opened RPM files, via disrpm or rpm2cpio, but there may be corner cases in which cpio is preferable to tar.

History and popularity

Both tar and cpio are competing archive formats that were introduced in Version 7 Unix in 1979 and then included in POSIX.1-1988, though only tar remained in the next standard, POSIX.1-20011.

Cpio's file format has changed several times and has not remained fully compatible between versions. For example, there is now an ASCII-encoded representation of binary file information data.

Tar is more universally known, has become more versatile over the years, and is more likely to be supported on a given system. Cpio is still used in a few areas, such as the Red Hat package format (RPM), though RPM v5 (which is admittedly obscure) uses xar instead of cpio.

Both live on most Unix-like systems, though tar is more common. Here are Debian's install stats:

#rank  name    inst    vote    old  recent  no-files  (maintainer)
   13   tar  189206  172133   3707   13298        68  (Bdale Garbee)
   61  cpio  189028   71664  96346   20920        98  (Anibal Monsalve Salazar)

Modes

Copy-out: This is for archive creation, akin to tar -pc

Copy-in: This is for archive extraction, akin to tar -px

Pass-through: This is basically both of the above, akin to tar -pc … |tar -px but in a single command (and therefore microscopically faster). It's similar to cp -pdr, though both cpio and (especially) tar have more customizability. Also consider rsync -a, which people often forget since it's more typically used across a network connection.

I have not compared their performance, but I expect they'll be quite similar in CPU, memory, and archive size (after compression).

like image 170
Adam Katz Avatar answered Sep 23 '22 17:09

Adam Katz