From 8b3550d1c20cac9946b8bd13fc35e175c091a967 Mon Sep 17 00:00:00 2001 From: Alan Hicks Date: Wed, 24 Feb 2010 16:22:13 -0500 Subject: This should be feature-complete now. The section on tar and archive files should be complete, but I'm willing to hear feedback on this critical part. --- chapter_04.xml | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/chapter_04.xml b/chapter_04.xml index 794113e..96cb46c 100644 --- a/chapter_04.xml +++ b/chapter_04.xml @@ -457,9 +457,100 @@ So great, we know how to compress files using all sorts of programs, but none of them can archive files in the way that zip does. That is until now. The Tape Archiver, or tar(1) is the most frequently -used archival program in Slackware. +used archival program in Slackware. Like other archival programs, +tar generates a new file that contains other +files and directories. It does not compress the generated file (often +called a "tarball") by default; however, the version of +tar included in Slackware supports a variety +of compression schemes, including the ones mentioned above. + +Invoking tar can be as easy or as +complicated as you like. Typically, creating a tarball is done with the +-cvzf arguments. Let's look at these in depth. + + + +tar Arguments + + + + Argument + Meaning + + + + + c + Create a tarball + + + x + Extract the contents of a tarball + + + t + Display the contents of a tarball + + + v + Be more verbose + + + z + Use gzip compression + + + j + Use bzip2 compression + + + J + Use LZMA compression + + + p + Preserve permissions + + + +
+ + +tar requires a bit more precision than other +applications in the order of its arguments. The -f argument +must be present when reading or writing to a file for example, and the +very next thing to follow must be the filename. Consider the following +examples. + + +darkstar:~$ tar -xvzf /tmp/tarball.tar.gz +darkstar:~$ tar -xvfz /tmp/tarball.tar.gz + + +Above, the first example works as you would expect, but the second +fails because tar has been instructed to +open the z file rather than the expected +/tmp/tarball.tar.gz. + + + +Now that we've got our arguments straightened out, lets look at a few +examples of how to create and extract tarballs. As we've noted, the +-c argument is used to create tarballs and -x +extracts their contents. If we want to create or extract a compressed +tarball though, we also have to specify the proper compression to use. +Naturally, if we don't want to compress the tarball at all, we can +leave these options out. The following command creates a new tarball +using the gzip compression alogrithm. While +it's not a strict requirement, it's also good practice to add the .tar +extension to all tarballs as well as whatever extension is used by the +compression algorithm. + + +darkstar:~$ tar -czf /tmp/tarball.tar.gz /tmp/tarball/ + -- cgit v1.2.3