Compressing a file just means making it smaller so that it takes up less hard-disk space. It’s like filling a toy box, closing the lid, then sitting on it to moosh the contents so that they fit into a smaller space. Any time you create a file that you’ll be sending via FTP or that people will access through the Web, you’ll want to compress the file so that it takes less time to send and download. As Code Listing 13.8 shows, you compress files using the compress command.
[ejr@hobbes compression]$ ls -l l* -rw-r-r-1 ejr users 501760 Jul 27 → 10:06 labrea.tar [ejr@hobbes compression]$ compress → labrea.tar [ejr@hobbes compression]$ ls -l l* -rw-r-r-1 ejr users 297027 Jul 27 → 10:06 labrea.tar.Z [ejr@hobbes compression]$ |
compress labrea.tar
At the shell prompt, type compress followed by the filename. Here, we’re compressing a tarred file, which contains multiple files. As you can see in Code Listing 13.8, the compressed file has a new extension (.Z) that shows that it’s compressed, and it replaces the original, uncompressed file.
✓ Tips
You can compress only one file at a time. If you have multiple files you want to compress, consider archiving them first using tar, and then compressing the single archived file. See the section called Archiving with tar earlier in this chapter.
You can add the -c flag to compress to leave the original file untouched and send the compressed version to standard output (where you’ll probably specify a name and save it to a file). For example, you might use compress -c labrea.tar > labrea.tar.Z. See Chapter 1 for some mighty interesting information on redirecting output, as is shown here.