From 0d7ad4c6efc1f46e201124d4e0971d9e02d78ff9 Mon Sep 17 00:00:00 2001 From: Alan Hicks Date: Wed, 24 Feb 2010 01:02:31 -0500 Subject: Added 'Archive Commands' section. zip, gzip, and bzip2 explained thus far. --- chapter_04.xml | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) (limited to 'chapter_04.xml') diff --git a/chapter_04.xml b/chapter_04.xml index 0057cb2..0e37ca8 100644 --- a/chapter_04.xml +++ b/chapter_04.xml @@ -97,6 +97,14 @@ printf (3) - formatted output conversion 8 System Administration + + 9 + Kernel API Descriptions + + + n + "New" - typically used to Tcl/Tk + @@ -305,6 +313,124 @@ bar_2/ +
+Archive and Compression + + +Everyone needs to package a lot of small files together for easy +storage from time to time, or perhaps you need to compress very large +files into a more manageable size? Maybe you want to do both of those +together? Thankfully there are several tools to do just that. + + +
+zip and unzip + + +You're probably familiar with .zip files. These are compressed files +that contain other files and directories. While we don't normally use +these files in the Linux world, they are still commonly used by other +operating systems, so we occasionally have to deal with them. + + + +In order to create a zip file, you'll (naturally) use the +zip(1) command. You can compress either +files or directories (or both) with zip, but +you'll have to use the -r argument for recursive action in +order to deal with directories. + + +darkstar:~$ zip -r /tmp/home.zip /home +darkstar:~$ zip /tmp/large_file.zip +/tmp/large_file + + +The order of the arguments is very important. The first filename must +be the zip file to create (if the .zip extension is ommitted, +zip will add it for you) and the rest are +files or directories to be added to the zip file. + + + +Naturally, unzip(1) will decompress a zip +archive file. + + +darkstar:~$ unzip /tmp/home.zip + +
+ +
+gzip + + +One of the oldest compression tools included in Slackware is +gzip(1), a compression tool that is only +capable or operating on a single file at a time. Whereas +zip is both a compression and an archival +tool, gzip is only capable of compression. +At first glance this seems like a draw-back, but it is really a +strength. The UNIX philosophy of making small tools that do their small +jobs well allows them to be combined in myriad ways. In order to +compress a file (or multiple files), simply pass them as arguments to +gzip. Whenever +gzip compresses a file, it adds a .gz +extension and removes the original file. + + +darkstar:~$ gzip /tmp/large_file + + +Decompressing is just as straight-forward with +gunzip which will create a new uncompressed +file and delete the old one. + + +darkstar:~$ gunzip /tmp/large_file.gz +darkstar:~$ ls /tmp/large_file* +/tmp/large_file + + +But suppose we don't want to delete the old compressed file, we just +want to read its contents or send them as input to another program? +The zcat program will read the gzip file, +decompress it in memory, and send the contents to the standard output +(the terminal screen unless it is redirected, see the next chapter for +more details on output redirection). + + +darkstar:~$ zcat /tmp/large_file.gz +Wed Aug 26 10:00:38 CDT 2009 +Slackware 13.0 x86 is released as stable! Thanks to everyone who helped +make this release possible -- see the RELEASE_NOTES for the credits. +The ISOs are off to the replicator. This time it will be a 6 CD-ROM +32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD. We're taking +pre-orders now at store.slackware.com. Please consider picking up a copy +to help support the project. Once again, thanks to the entire Slackware +community for all the help testing and fixing things and offering +suggestions during this development cycle. + + +
+ +
+bzip2 + + +One alternative to gzip is the +bzip2(1) compression utility which works in +almost the exact same way. The advantage to +bzip2 is that it boasts greater compression +strength. Unfortunately, achieving that greater compression is a slow +process, so bzip2 takes longer to run than +other alternatives. + + +
+ +
+
Reading Documents -- cgit v1.2.3