Linux Server Configuration
Chapter 2: Compressing And Archiving Files
Download 493.5 Kb.
|
0501-linux-server-configuration
- Bu sahifa navigatsiya:
- 2.1 Compress A File Using: bzip2
Chapter 2: Compressing And Archiving FilesLarge files use a lot of disk space and take longer than smaller files to transfer from one system to another over a network. If you do not need to look at the contents of a large file very often, you may want to save it on a CD, DVD, or another medium and remove it from the hard disk. If you have a continuing need for the file, retrieving a copy from a CD may be inconvenient. To reduce the amount of disk space you use without removing the file entirely, you can compress the file without losing any of the information it holds. Similarly a single archive of several files packed into a larger file is easier to manipulate, upload, download, and email than multiple files. You may frequently download compressed, archived files from the Internet. The utilities described in this section compress and decompress files and pack and unpack archives. 2.1 Compress A File Using: bzip2The bzip2 utility compresses a file by analyzing it and recoding it more efficiently. The new version of the file looks completely different. In fact, because the new file contains many nonprinting characters, you cannot view it directly. The bzip2 utility works particularly well on files that contain a lot of repeated information, such as ext and image data, although most image data is already in a compressed format. The following example shows a boring file. Each of the 8,000 lines of the letter_e file contains 72 e’s and a NEWLINE character that marks the end of the line. The file occupies more than half a megabyte of disk storage. $ ls -l -rw-rw-r-- 1 sam sam 584000 Mar 1 22:31 letter_e The –l (long) option causes ls to display more information about a file. Here it shows that letter_e is 584,000 bytes long. The ––verbose (or –v) option causes bzip2 to report how much it was able to reduce the size of the file. In this case, it shrank the file by 99.99 percent: $ bzip2 -v letter_e letter_e: 11680.00:1, 0.001 bits/byte, 99.99% saved, 584000 in, 50 out. $ ls -l -rw-rw-r-- 1 sam sam 50 Mar 1 22:31 letter_e.bz2 Now the file is only 50 bytes long. The bzip2 utility also renamed the file, appending .bz2 to its name. This naming convention reminds you that the file is compressed; you would not want to display or print it, for example, without first decompressing it. The bzip2 utility does not change the modification date associated with the file, even though it completely changes the file’s contents. In the following, more realistic example, the file zach.jpg contains a computer graphics image: $ ls -l -rw-r--r-- 1 sam sam 33287 Mar 1 22:40 zach.jpg The bzip2 utility can reduce the size of the file by only 28 percent because the image is already in a compressed format: $ bzip2 -v zach.jpg zach.jpg: 1.391:1, 5.749 bits/byte, 28.13% saved, 33287 in, 23922 out. Download 493.5 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling