File Compression from the Shell

 < Day Day Up > 



Many people find that from time to time they need to compress several files into one archived file. There can be many reasons for doing this. One reason is to archive old files that you don’t use but do not want to destroy. Most archiving tools also compress the files, so that the archived file takes up less disk space than the original file did. However, you should be aware that compression is not always part of compiling files into an archive file. With some archive tools, compression is an option that you choose to add or not to add. Another reason to archive files is to send them over the Internet. If you have five files to send, compressing them into a single archive would make it easier to send them.

There are several programs available for Windows that do this sort of archiving. Perhaps the most popular is WinZip®. WinZip is a shareware program, which means you can download a free trial version. It has a very user-friendly graphical interface that enables you to compress files into an archive and extract them from that archive with ease.

Just as Windows users need the capability to archive and extract files, so do Linux users. There is a very interesting Linux utility that works from the shell called tar. The tar program can be used to compress files and to extract them. It comes with all Linux distributions, so if you send a tar file to a friend or colleague who is using Linux, you can rest assured that he will have the necessary tools to extract the files. Since tar is a shell command, you might have guessed that there are several flags you can pass to it to make it do what you require. Table 19.3 illustrates the most important of these flags. You can get a complete list at the shell by typing in tar –help.

Table 19.3: The tar Flags

The Flag

The Flag’s Purpose

-c

This flag is used to create a new archive file.

-x

This flag is used to extract files from an archive.

-r

This flag is used to append new files to an existing archive.

-f

This is used in working with a file.

-t

This is used simply to list the contents of an archive file.

-t

This is used to list the contents of an archive file.

-v

This is often used with –t. It designates a verbose response.

-z

This flag directs the tar to use gzip compression.

Let’s take a look at these files in action. In Figure 19.19 you can see that an ls command was executed to see what files were in the current directory. Then the tar command was used to create a new archive file. This was done by typing tar, followed by the flags for create (c) and file (f) and the new archive file’s name, then the files to add to this archive were listed.

click to expand
Figure 19.19: Creating a tar file.

If you want to view the content of an existing file, you would again use the tar command, only with different flags. This is shown in Figure 19.20, where we first use ls to list the directory’s contents, then use tar with the flags to list (t), file (f), and verbose output (v).

click to expand
Figure 19.20: Listing the contents of a tar file.

Tar is a very commonly used utility in all Unix-like operating systems. You will find that many software packages that are distributed for Unix or Linux on the Internet come as tar files, frequently called tarballs. This means that you can get a lot of useful programs for Linux, most of which are free, from the Internet. But it also means you will need to know how to use tar to decompress those files.



 < Day Day Up > 



Moving From Windows to Linux
Moving From Windows To Linux (Charles River Media Networking/Security)
ISBN: 1584502800
EAN: 2147483647
Year: 2004
Pages: 247
Authors: Chuck Easttom

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net