Archiving Tools
Info-ZIP | GNU tar | Gzip
Info-ZIP zip and unzip
These are 32-bit console programs that are fully compatible with
Windows. Info-ZIP programs are available for free (as in beer and as in speech), and exist on a
variety of operating systems. They are mostly compatible with
PKZIP archives.
To archive a single file:
zip zipfile.zip filename.ext
where:
zipfile.zip is
the name of the zip file that will be created or updated
filename.ext is
the name of the file that added to the zip file
For example:
zip backup.zip mycopy.bat
To archive multiple files (in the current working directory):
zip zipfile.zip wildcard
zip zipfile.zip file1 file2 ...
where:
zipfile.zip is
the name of the zip file that will be created or updated
wildcard is
either * (all files) or *.ext
(all files with the same extension)
For example:
zip batchfiles.zip *.bat
zip batchfiles.zip mycopy.bat mbcopy.bat lab3parta.bat
To archive an entire directory (including subdirectories):
zip -r zipfile.zip directory
zip -r zipfile.zip directory1 directory2 ...
where:
zipfile.zip is
the name of the zip file that will be created or updated
directory is the name of a directory
(folder) -- you can specify more than one at a time
For example:
zip -r documents.zip "c:\My Documents"
zip -r labs.zip lab1 lab2 lab3
To use Maximum Compression:
Add -9 to your zip
command
line.
For example:
zip -r -9 documents.zip "c:\My Documents"
zip -r9 documents.zip "c:\My Documents"
zip -9 batchfiles.zip *.bat
zip -9 backup.zip mycopy.bat
To view the contents of a zip archive:
unzip -l zipfile.zip
To delete a file from a zip archive:
zip -d zipfile.zip filename
To unzip all files and directories from a zip archive:
unzip zipfile.zip
Info-ZIP unzip will automatically create subdirectories, if they exist
in the zip archive.
To unzip only certain files or directories from a zip archive:
unzip zipfile.zip filename
unzip zipfile.zip directory
To unzip files created on another operating system:
If you use Info-ZIP zip to zip files on, say a Linux PC or Solaris
workstation, you can unzip them on a Windows PC and properly convert
the text files (so you can edit them.) The same works when
transfering a zip file created on Windows to Linux or Solaris.
unzip -a zipfile.zip
GNU tar
The tar program was originally designed to control a tape drive on a
UNIX system (tar actually stands for "tape
archive".) With the popularity of free UNIX (and Linux)
software on the WWW, tar is a popular format for archiving files.
Windows versions of tar exist; some of them are better than others.
To archive a single file:
tar cf tarfile.tar filename.ext
tar cvf tarfile.tar filename.ext
where:
tarfile.tar is
the name of the tar file that will be created -- note: tar will overwrite,
instead of updating, previously existing tar files
filename.ext is
the name of the file that added to the tar file
The c means "create"; the f means create a tar file instead of
trying to use a tape drive (which most computers do not have.)
The v, which is optional, will
list the filename as it is archived.
For example:
tar cf backup.tar mycopy.bat
tar cvf backup.tar mycopy.bat
To archive multiple files or directories:
tar cf tarfile.tar wildcard
tar cf tarfile.tar file1
file2 ...
tar cf tarfile.tar directory1
directory2 ...
tar cf tarfile.tar directory1
file2 file3 wildcard4 directory5 ...
where:
wildcard is
either * (all files) or *.ext
(all files with the same extension)
By default, tar includes subdirectories. You can also use cvf to list files and directories as
they are archived.
For example:
tar cf batchfiles.tar *.bat
tar cf batchfiles.zip mycopy.bat mbcopy.bat lab3parta.bat
tar cvf labs.tar lab1 lab2 lab3
tar cvf work.tar lab* *.bat
To view the contents of a tar archive:
tar tf tarfile.tar
tar tvf tarfile.tar
Here, the v will displayed
detailed file information. Without it, only file and directory
names are displayed.
To extract all files from a tar archive:
tar xf tarfile.tar
tar xvf tarfile.tar
Tar will automatically create subdirectories, if they exist
in the tar archive. Here, the v
will list filenames and directories as they are extracted.
To extract a single file or directory from a tar archive:
tar xf tarfile.tar
filename
tar xvf tarfile.tar
filename
tar xf tarfile.tar
directory
tar xvf tarfile.tar
directory
This may take a while for a large tar file, as tar starts searching for
the file or directory from the beginning, and does not stop until it
reaches the end of the tar file (even if it already found the file or
directory that you want.)
Gzip
The Gzip tool is used only for compression; not for archiving. It
is usually combined with tar to produce a tarball
-- which is a gzip-compressed tar archive.
To compress a file:
gzip filename.ext
where:
filename.ext is
the name of any file. Gzip will compress it and rename it to filename.ext.gz
To use Maximum Compression:
gzip -9 filename.ext
For large files, this may take a while. Without the
-9, Gzip uses its default
compression level (equivalent to a -5).
To uncompress a file:
gzip -d filename.ext.gz
gunzip filename.ext.gz
Gzip will uncompress the file and remove the .gz extension. Some computers
will have gunzip installed;
others will only have gzip.
To create a tarball:
tar cf tarfile.tar file(s)
gzip -9 tarfile.tar
where:
tarfile.tar is
the name of the tar file that will be created
file(s) is
the list of filenames and/or directories that will be archived
This will create a file called tarfile.tar.gz -- a tarball.
On some systems, you can use a pipe to create the tarball using one
command line:
tar cf -
file(s) | gzip -9 -c > tarfile.tar.gz
The - tells tar to
write its output to the pipe, instead of to a tar file. The
-c tells gzip to write
its output to the terminal (window), and the > captures this output and
redirects it to the tarball file.
On some systems, GNU tar will be aware of Gzip, so that you can create
a tarball using a single command. Gzip will use its default
compression level.
tar zcf tarfile.tar.gz file(s)
To extract a tarball:
The gzip and tar
commands are basically reversed:
gzip -d tarfile.tar.gz
tar xf tarfile.tar
On some systems, you can use a pipe to extract a tarball using one
command line:
gzip -d -c tarfile.tar.gz | tar xf -
The - tells tar to
read its output from the pipe, instead of from a tar file. The -c tells gzip to write its
uncompressed output to the pipe.
On some systems, GNU tar will be aware of Gzip, so that you can extract
a tarball using a single command:
tar zxf tarfile.tar.gz
This way, and the pipe way, the tarball remains
compressed.
To list the contents of a tarball:
Unfortunately, if your tar command is not aware of gzip or does not
work with pipes, you have to uncompress the tarball first:
gzip -d tarfile.tar.gz
tar tf tarfile.tar
On some systems, you can use a pipe to list the tarball using one
command line:
gzip -d -c tarfile.tar.gz | tar tf -
On some systems, GNU tar will be aware of Gzip, so that you can list
a tarball using a single command:
tar ztf tarfile.tar.gz
Using this way, and the pipe way, the tarball remains compressed.
Using bzip2 instead of gzip:
On some systems,
GNU bzip2 will be
installed. It typically has higher compression ratios than Gzip,
but (as a result) generally takes longer to compress. Tarballs
compressed with bzip2 have a .bz2
extension. Similar commands are used to handle Bzip2 tarballs:
tar cf -
file(s) | bzip2 -9 > tarfile.tar.bz2
bzip2 -d -c tarfile.tar.bz2 | tar xf -
bzip2 -d -c tarfile.tar.bz2 | tar tf -
Newer versions of GNU tar are also aware of Bzip2, using the j option:
tar jcf tarfile.tar.bz2 file(s)
tar jxf tarfile.tar.bz2
tar jtf tarfile.tar.bz2
Back to the CTEC1430 page
| Info-ZIP | GNU tar | Gzip