Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
Reposted here: stackoverflow.com/questions/2966409 –  Tom Zych Oct 15 at 11:17

3 Answers 3

up vote 4 down vote accepted

This is an extremely generic overview:

CPIO does a better job of duplication a file system, including taking backups. It preserves things like hardlinks, fifos, and other not-a-standard-file features. Most implementations of CPIO do everything TAR does, including reading and writing .tar files. CPIO usually takes a list of files from standard input to archive; this makes it very easy to pipe a list from something else (like find).

CPIO passthrough is very useful if you have a very long list of files you want to copy from directory A to directory B. (For example, you could use find to locate all files that have changed in the last 2 years on your system)

TAR does a better job of simply dumping all your standard files to/from a tape (or archive file). It's a bit simpler to use (for most common tasks). It meets most people's simple backup demands easily; and most of it's popularity is from this fact.

And now for the fine print. There's several different versions and implementations of both CPIO and TAR. Each one has different features and some have different command line options. There are things that each can do where the other can not; if you find yourself limited by one, try the other. Everyone has a favorite, and 99% of the time either will accomplish the task.

share|improve this answer

On AE 3 redhat, I found that cpio had a size limitation of 2 GBytes on an output stream. However, tar did not have this limitation.

Other systems might have different limitations.

share|improve this answer

I prefer CPIO too. However, when using cpio on file set of an unknown origin (like files created by end users) it is better work with NUL-terminated file names: use -print0 flag to find and add 0 flag to cpio. This way files with weird names (like ones including CR NL characters) will be treated correctly.

cd / && find . -xdev -print0 | cpio -pmdu0 /mnt/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.