- slide 1 of 5
ZIP is perhaps one of the oldest compression formats, dating back to 1989 with PKZIP, which is in fact an evolution from the ARC compression format. ZIP compressed files have the extension .zip or .ZIP but there are also other files which have “zip" in their names but have nothing to do with ZIP. One example of them is the GZIP format which we have discussed in our previous article. The programs that are used to compress and unpack ZIP files are different; you cannot open a GZIP file with a ZIP file handler.
In the old days, when users needed to carry files on floppy disks, which had a capacity of 1.44MB, transferring files larger than this size was a big issue. ZIP was one of the formats that offered file compression and file spanning. For example, if you had a file of 3MB, you could zip it to, say, 2.5MB and inform the ZIP program to split the archive so that it could be transferred by floppy disks. The program would automatically create ZIP archives of 1.4MB and 1.1MB, you could then copy them to two floppies, and in the other computer, copy the files into the same directory and double click the first file to open the whole archive. This, as you can imagine, was a very handy feature. Now, you can instruct your ZIP program to create split archives of any size, say to fit in a CD. These split files have extensions of .z01, .z02 etc. The function to encrypt zip files with a password was also added.
To open a ZIP file in Linux, there are two options: you can go with the command line or you can go with a graphical program. Archive Manager or ARK can open the individual ZIP archives or split files without any problems: double click on the file and the default archive handling program will be opened. Click on the “Extract" button and the files can be unzipped to a directory of your choice.
Personally I find using the command line interface easier to handle. To work with ZIP files, you need to have the unzip package installed. If it is not installed, you can download and install it through your package manager. If everything is in place, change into the directory in which you have the zip file(s) and issue unzip package_name.zip. If there are split archives, they will be recognized and unpacked. If the ZIP file is password protected, then the command becomes unzip -Ppassword package_name.zip. Note that this can be insecure because someone can peek over your shoulder and learn your password.
Sometimes with split archives the unzip command may not complete its operation. If this is the case, 99% of the time opening the compressed archive with a graphical program such as Archive Manager will let you extract the files.
- slide 2 of 5
Read on for handling RAR files and creating ZIP and RAR archives.
- slide 3 of 5
In Linux it is easy to work with compressed files and the necessary tools. Now we look at how to open a rar file in Linux. We conclude our article by creating rar and zip archives. Of course the rar file extractor and the rar utility are free.
- slide 4 of 5
RAR is a proprietary file format developed by Eugene Roshal (“RAR" stands for Roshal Archive) supporting error recovery and file spanning in addition to compression. RAR files are very similar to ZIP files except for their compression method. However, the error recovery feature gives RAR a distinct advantage (see the next section for error recovery.)
You again have two options to unpack rar files: command line and graphical programs. Archive Manager, ARK and File Roller programs work nicely with RAR files. For the command line, you have to change to the directory in which you have the RAR files and then issue the command unrar x archive_name.rar to extract the files. The x option means “here", in other words, extract the contents of the archive to the directory you are in. If the RAR archive is password-protected, then you have to issue the command with the p option, where you specify the password: unrar x -ppassword archive_name.rar.
- slide 5 of 5
Creating ZIP and RAR Archives
The easiest way to create ZIP and RAR archives is by using a graphical tool. Open your distribution’s file manager, select the files you want to archive and right-click on them. Select the archiving option and choose the directory where you want your archive to be saved.
In the command line, you can create a ZIP archive with the zip -r archive_name.zip file1 file2 command, where file1 and file2 stand for the files you want to add to your ZIP archive (you can specify as many as you want.) For the RAR part, you can go with the syntax rar a archive_name.rar file1 file2, which, the same way, adds file1 and file2 to your RAR archive.
Of course you are not limited to creating and extracting ZIP and RAR archives. You have many options to play with them, such as password-protecting them, splitting them etc. Don't forget to check their man pages.
Linux File Compression - ZIP and RAR
In this article series we look at the various compression formats present in the Linux world and the ways to handle them. We also look at the most common error with the compressed archives, the CRC Check Error.