Java Reference
In-Depth Information
Table 1.5
Examples of the
zip
and
unzip
commands
Command
Explanation
unzip -l packedup.zip
Gives a table of contents of the archive with some extra frill
around the edges, like a count of the files in the archive.
unzip packedup.zip
Extracts all the files from the ZIP file, creating them
according to their specified pathname, assuming your user
ID and file permissions allow it. Add the quiet option with
-q
if you would like
unzip
not to list each file as it unzips it.
zip -r packedup mydir
Creates a ZIP archive named
packedup.zip
from the
mydir
directory and its contents. The
-r
tells
zip
to
recursively descend into all the subdirectories, their
subdirectories, and so on; otherwise,
zip
will just take the
files at the first layer and go no deeper.
TIP
Since TAR and ZIP files can contain absolute as well as relative pathnames, it
is a good idea to look at their contents (e.g.,
tar tvf file
) before unpacking
them, so that you know what is going to be written where.
There are many, many more options for
tar
and
zip
that we are not cover-
ing here, but these are the most common in our experience, and they will give
you a good start.
The
tar
and
zip
commands are also worth knowing about by a Java devel-
oper because of their relationship to
JAR files
. If you are working with Java you
will soon run across the notion of a Java ARchive file, or JAR file. They are
recognizable by name, ending in
.jar
. Certain Java tools are built to under-
stand the internal format of JAR files. For Enterprise Java (J2EE) there are
similar archives known as WAR files and EAR files. The command syntax for
dealing with the
jar
command that builds these archives is very similar to the
basic commands of
tar
. The internal format of a
jar
is the same as a ZIP file.
In fact, most places where you can use a JAR file you can use a ZIP file as well.
(You will see more about this when we discuss the standard Java tools in
Section 5.11.)