cpio - copy files to and from archives

I found this command when I picked up Unix in Easy Steps Went to page 40~ and saw how to make backups. Thought “pfft they will just use tar”. And there it was cpio, never head of it before. Book said that its commonly used to create archives, madness.

ls | cpio -ov > directory.cpio

Stick all the files in the current directory into an archive directory.cpio. -o creates and -v verbose.

Extracting an archive requires a bit more thought because cpio will not create directories by default. Another characteristic, is it will not overwrite existing files unless you tell it to.

cpio -iv < directory.cpio

This will retrieve the files archived in the file directory.cpio and place them in the present directory. The -i option extracts the archive 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 to the current directory. If you try to extract the files on top of files of the same name that already exist (and have the same or later modification time) cpio will not extract the file unless told to do so by the -u option.

https://www.gnu.org/software/cpio/manual/html_node/index.html