Next Previous Contents

6. Archives, Distributions and File Compression

There are two issues here.

Exchanging file packages with people can be a challenge. You need to know what the other user's operating system can do, as well as what the other user can do. Linux, out of the box, can unpack just about anything generated on Microsoft Windows. Windows users require software in addition to the standard Windows distribution to unpack archives. You can exchange files with MacIntosh users, but you may have to install some software.

Usually, file packages are compressed, to save disk space and download time.

6.1 Tape Archives

Tape archives were originally intended as a format for writing to magnetic tape. They are now used systematically to distribute GNU free software, usually with some sort of data compression. They are not used much outside the UNIX/Gnu world.

tar -cf archive.tar foobar

Create an archive called archive.tar from foobar, which almost certainly is a directory. There would be no point to doing this to an individual file.

tar -cv archive.tar foo bar barfoo foobar

Create an archive called archive.tar from the files or directories foo, bar, barfoo and foobar.

tar -cvf archive.tar foobar

Create an archive called archive.tar from foobar. The v switch means verbose output. You will see a file listing printed to the screen as your archive is created.

tar -zcf archive.tar.gz foobar

Create an archive called archive.tar from foobar, and then compress it using Gnuzip. This works only on systems using Gnu tar. Linux comes with Gnu tar. An alternate file extension for Gnu zipped tar files is *.tgz.

tar -cf /dev/fd0 foobar

Write out your tar format file directly to a storage device. On Linux, /dev/fd0 is a floppy drive. There is no need to format the floppy. It will be in tar format. This should work on just about any writable device other than a read-write CD-ROM. To use a CD-ROM for backup, you will have to write your file to a file on the hard drive, then use your CD recording tool to transfer it to CD-ROM. To write directly to devices, you almost certainly have to be logged in as root.

tar -tvf archive.tar

Print out a list of the files in archive.tar.

tar -tvf /dev/fd0

As above, except that /dev/fd0 is a floppy disk on a Linux box.

tar -ztvf archive.tar.gz

As above, except that this time, the tar is written to a CD-ROM.

tar -ztvf archive.tgz

Print out the directory of a Gnu zipped tar file. This only works on Gnu tar.

tar -xf foobar.tar

Unpack the archive foobar.tar. By unpack, I mean that the files contained in the archive will be written out to the current directory.

tar -xvf foobar.tar

As above, but this time, print out the list of files being unpacked.

tar -zxf foobar.tgz

Unpack the Gnuzipped archive foobar.tgz. This only works with Gnu tar. As noted above, a Gnuzipped tar file can have the extension *.tar.gz. By unpack, we mean that the files contained in the archive will we written out to the current directory.

tar -zxvf foobar.tgz

As above, but print the list of files being unpacked.

The switches c, t and x are used to Create, lisT and eXtract files to and from the archive. The f switch indicates you are providing a pathname to something other than your default tape device. The v switch requests Verbose output, which means that tar lists each files as it adds it or extracts it to/from the archive. If you want to list an archive using the t switch, you must use the verbose switch as well. The z switch works only in Gnu tar, and it activates Gnu zip.

If you are not running Gnu tar, you do not have the z switch to activate Gnu zip. You will have to uncompress the archive with Gnu zip as a separate operation. Heck, you may have to install Gnu zip!

The command line switch dash (``-'') is optional with Gnu tar, and possibly, some of the other versions.

If you are preparing to unpack an archive, you should always check the contents to verify that it will unpack into a new subdirectory. Unpacking an archive into an existing directory that already has a lot of stuff in it usually results in a mess.

Microsoft Windows users can unpack tar files, even if they have been Gnuzipped. WINZIP supports the format. WINZIP first removes the gnuzip, providing you with the tar file. When I did this, I had to change the tar file's name from foobar_tar to foobar.tar. Then, WINZIP unpacks it.

6.2 Gnuzip and Bzip

The commands gzip, gunzip, bzip2 and bunzip2 are file compression utilities.

gzip foo

Compress the file foo. The compressed file will be saved as foo.gz.

bzip2 foo

Compress the file foo. The compressed file will be saved as foo.bz2.

gunzip foo

Uncompress the file foo. Gzip does not require you to type in the extension.

bunzip2 foo.bz2

Uncompress the file foo. Bunzip2 requires you to type in the whole filename.

Gzip and Bzip are installed with most new Linux distributions. Both are available as Gnu free software with source code. On Microsoft Windows, WINZIP can uncompress gzipped files.

6.3 Zip

The UNIX command zip manages file archives compatible with the standard MS-DOS and Windows PKzip and WINZIP format. This is the recommended format for exchanging archives with Microsoft Windows users.

zip

Get a brief description of the command zip.

zip -r foobar.zip foobar

Create a zip file foobar.zip from the directory foobar.

unzip -l foobar.zip

Print out a list of the contents of foobar.zip. Always do this before unpacking the archive. You want to know where the files are going to be written.

unzip foobar.zip

Unpack the archive foobar.zip.

Pkzip is available for Linux. This is the original program for generating *.zip archives. The program even supports self-unpacking archives. Unfortunately, they self-unpack on Linux, not on Windows, where you are more likely to have users without archiving programs.

6.4 Rar

I believe this is being pushed as the latest archiving program for Microsoft Windows. There is an unrar program for Linux, but you may have to search for and install it.

The publisher RARLAB, has Linux and FreeBSD versions of their software. These are shareware, and you are expected to pay for a license. I have not played with them much. They provide command line help.

6.5 Compress

Historically, UNIX files were compressed using the command compress. This might be available on your system. The compressed files usually have the extension *.Z.

compress foobar

Compress the file foobar. The name will be changed to foobar.Z.

uncompress foobar

Uncompress the file foobar.Z. The name will be changed back to foobar. You don't have to tell compress about the file extension.

I don't think this is used much anymore. It is not installed on Fedora 15.

6.6 Red Hat Package Manager

This an important standard for distributing Linux binaries. It is quite an elaborate program. To understand it properly, you will have to read Red Hat's documentation. The following instructions will enable you to inspect, install and uninstall software from RPMs. Rpm provides quite a bit of information if you run it by itself, without operands. Most of the time, rpm will not install or uninstall software unless you are logged in as root.

rpm -qlp foobar.rpm

List the contents of the RPM file foobar.rpm

rpm -i foobar.rpm

Install the package foobar.rpm. Rpm will check your system for dependencies before installing the package. Rpm will refuse to install foobar if a current or later version of foobar is already installed, or if some package required by foobar has not already been installed.

rpm -i --nodeps foobar.rpm

Install the package foobar.rpm. Do not check for dependencies. Dependency checking can be frustrating at times, but you had had better know exactly what you are doing if you want to skip them. You have been warned!

rpm --erase foobar

Remove the package foobar from your system. Again, the dependencies are checked, and foobar will not be removed if some other package requires it.

rpm --erase --nodeps foobar

Be very, very careful with this. See my remarks above.

rpm -q foobar

Print out brief information on package you have already installed on your system. Basically, you get the version number. Read the rpm documentation for more information on this.

rpm -qa

Print out a list of all the packages installed by rpm.

Red Hat's yum command also installs rpm files, but it searches for the files and dependencies out on the internet.

6.7 Slackware Packages

Slackware installs its binaries from *.tgz files which have a little script embedded in them. You should try to use Slackware's package manager to install these things, but tar zxf will do in a pinch.

6.8 Debian Packages

I have experience whatsovever with Debian packages. Sorry.

6.9 MacIntosh Archives

I haven't had much practise with MacIntoshes. Most Linux packages come with something called macutils, which contains things for communicating with MacIntosh computers. This could not unpack the one MacIntosh file I have received.

I had to install the package uudeview. You can get this from. http://www.uni-frankfurt.de/~fp/uudeview/ You will have to read the instructions.

Take a look at your kernel source. You can compile your kernel so that your Linux box can read MacIntosh floppies.


Next Previous Contents