tar - *NIX ArchivesEdit
cpio - Flexible Archiving ToolEdit
tar is the preferred method for creating archives, but in some cases a particular archive format may be desired and
cpio provides a greater degree of control over how the archive is generated at the cost of greater complexity.
To create a
cpio archive, the
-o option is provided (think 'o' for "The archive is being written out").
cpio expects a list of files to be provided to its standard input. The list of files is usually provided by piping results from the find command. The
-H option can be used to specify the archive format, see the man page for more information.
[user@station user]$ find playground/ playground/ playground/AUTHORS playground/ChangeLog playground/COPYING playground/foo.txt playground/newfile [user@station user]$ find playground/ | cpio -o >archive 1212 blocks [user@station user]$ ls -l archive -rw-rw-r-- 1 user user 620544 Jan 5 08:49 archive [user@station user]$ file archive archive: cpio archive
Listing contents of an archive with
To view the contents of an archive the
-i option is provided to tell
cpio to expect the archive data on its standard input. The
-t option is also used then to tell cpio to not extract, but rather simply list the contents of the archive.
[user@station user]$ cpio -it <archive playground/ playground/AUTHORS playground/ChangeLog playground/COPYING playground/foo.txt playground/newfile 1212 blocks
Extracting an archive with
-i option is used with a combination of options to tell it how to extract. Common choices include
-d to tell cpio to create directories as needed.
-m to reset file modification times.
-R to change file ownership.
[user@station user]$ cd /tmp [user@station tmp]$ cpio -idm <archive 1212 blocks [user@station tmp]$ find playground/ playground/ playground/AUTHORS playground/ChangeLog playground/COPYING playground/foo.txt playground/newfile
zip - PKZIP style archivesEdit
[user@station user]$ zip -r playground.zip playground adding: playground/ (stored 0%) adding: playground/AUTHORS (deflated 63%) adding: playground/COPYING (deflated 62%) adding: playground/foo.txt (stored 0%) adding: playground/newfile (deflated 39%) adding: playground/ChangeLog (deflated 70%) [user@station user]$ ls -l playground.zip -rw-r--r-- 1 user user 71607 Jan 11 14:33 playground.zip
Listing contents of a
[user@station user]$ unzip -l playground.zip Archive: playground.zip Length Date Time Name -------- ---- ---- ---- 0 01-11-05 14:33 playground/ 2110 01-11-05 14:32 playground/AUTHORS 17992 01-11-05 14:33 playground/COPYING 22 01-11-05 14:33 playground/foo.txt 44 01-11-05 14:33 playground/newfile 212169 01-11-05 14:32 playground/ChangeLog -------- ------- 232337 6 files
[user@station user]$ rm -rf playground [user@station user]$ unzip playground.zip Archive: playground.zip creating: playground/ inflating: playground/AUTHORS inflating: playground/COPYING extracting: playground/foo.txt inflating: playground/newfile inflating: playground/ChangeLog
dump - Filesystem Level BackupEdit