In this article you will learn how to create ZIP archives, list, test and extract them. After reading this article you will know how to manipulate ZIP archives on GNU/Linux systems. We already know that zip works well with tar from the Using TAR Command post. Let us discuss how to work with zip and unzip.
How to create a ZIP archive?
I believe learning by example is the easiest way. Let me walk you through an example straightaway. Let us assume we have two files - abc.txt and xyz.txt in the current working directory.
[sudheer@localhost zip]$ ls abc.txt xyz.txt
To compress the text files and to archive them use the below command:
zip foo *txt
The syntax we followed is:
zip zipfile list
In our example foo is the name of the ZIP archive file to be created. *txt is the list of files to be compressed and included in the ZIP archive.
The result of the above command is the creation of the file named foo.zip which contains the archive of the compressed files in the current working directory whose names end with txt.
We could also use
zip foo abc.txt xyz.txt
The output of the above command should look something like:
[sudheer@localhost zip]$ zip foo abc.txt xyz.txt adding: abc.txt (stored 0%) adding: xyz.txt (stored 0%) [sudheer@localhost zip]$ ls abc.txt foo.zip xyz.txt
How to extract a zip archive?
To extract a zip archive you use unzip. Zip and unzip are companion programs to each other. To extract a ZIP archive you just need to type unzip followed by the name of the archive. Here is an example. Let us extract the ZIP archive - foo.zip, we created in our previous example.
unzip foo.zip
Unzip can also list and test ZIP archives. To list the contents of a ZIP archive use the -l switch.
unzip -l foo.zip
The output of the above command looks like:
Archive: foo.zip
Length Date Time Name
-------- ---- ---- ----
13 03-23-08 21:58 abc.txt
13 03-23-08 21:44 xyz.txt
-------- -------
26 2 filesYou can test whether a ZIP archive is damaged using the -t option.
unzip -t foo.zip
[sudheer@localhost arc]$ unzip -t foo.zip
Archive: foo.zip
testing: abc.txt OK
testing: xyz.txt OK
No errors detected in compressed data of foo.zip.Isn't it very convenient to test a ZIP archive before extracting it, especially if the archive size is too large?
You can of course read more about zip and unzip in the manual pages and other documentation sources. This primer introduced you to the most common operations performed using zip and unzip.
Post new comment