How to zip and unzip files

Zip files have been the default file archive format on DOS since the 1980s.

On Linux, you may be familiar with the standard Unix archive command: tar. There's a version of tar on FreeDOS too (and a bunch of other popular archive programs), but the de facto standard archiver on DOS is Zip and Unzip. Both Zip and Unzip are installed in FreeDOS 1.3 RC4 by default.

The Zip file format was originally conceived in 1989 by Phil Katz of PKWARE, for the PKZIP and PKUNZIP pair of DOS archive utilities. Katz released the specification for Zip files as an open standard, so anyone could create Zip archives. As a result of the open specification, Zip became a standard archive on DOS. The Info-ZIP project implements an open source set of ZIP and UNZIP programs.

Zipping files and directories

You can use ZIP at the DOS command line to create archives of files and directories. This is a handy way to make a backup copy of your work or to release a "package" to use in a future FreeDOS distribution.

ZIP sports a ton of command-line options to do different things, but the command line options I use most are -r to process directories and subdirectories recursively, and -9 to provide the maximum compression possible. ZIP and UNZIP use a Unix-like command line, so you can combine options behind the dash: -9r will give maximum compression and include subdirectories in the Zip file.

For example, let's say I have a directory called BANANA, containing source code to a program I'm working on:

D:\SRC>dir /b banana
BANANA.C
GAME.C
PUTIMAGE.C
TOSS.C

To zip the directory and its contents, use the -r option:

D:\SRC>zip -r banana.zip banana
  adding: banana/ (stored 0%)
  adding: banana/putimage.c (deflated 59%)
  adding: banana/banana.c (deflated 66%)
  adding: banana/toss.c (deflated 56%)
  adding: banana/game.c (deflated 59%)

To always use the best possible compression on each file, add the -9 option:

D:\SRC>zip -9r banana.zip banana
  adding: banana/ (stored 0%)
  adding: banana/putimage.c (deflated 59%)
  adding: banana/banana.c (deflated 66%)
  adding: banana/toss.c (deflated 56%)
  adding: banana/game.c (deflated 59%)

Although in this case, the file compression was the same.

Unzipping files and directories

Saving files into a zip file is great, but you'll eventually need to extract those files somewhere. Let's start by examining what's inside the zip file we just created. For this, use the UNZIP command. You can use a bunch of different options with UNZIP, but I find I use just a few common options.

To list the contents of a zip file, use the -l ("list") option:

D:\SRC>unzip -l banana.zip
Archive:  banana.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  06-29-2024 20:25   banana/
     1156  06-29-2024 20:25   banana/putimage.c
     1374  06-29-2024 20:25   banana/banana.c
     1994  06-29-2024 20:25   banana/toss.c
     3280  06-29-2024 20:25   banana/game.c
---------                     -------
     7804                     5 files

The output allows me to see the 5 entries in the zip file: 4 files plus the BANANA directory entry.

If I want to extract the entire zip file, I could just use the UNZIP command and provide the zip file as a command-line option. That extracts the zip file starting at my current working directory. Unless I'm restoring a previous version of something, I usually don't want to overwrite my current files. In that case, I will want to extract the zip file to a new directory. You can specify the destination path with the -d ("destination") command-line option:

D:\SRC>unzip banana.zip -d b2
Archive:  banana.zip
   creating: b2/banana/
  inflating: b2/banana/putimage.c
  inflating: b2/banana/banana.c
  inflating: b2/banana/toss.c
  inflating: b2/banana/game.c

Sometimes I want to extract a single file from a zip file. In this example, let's say I wanted to extract the banana/putimage.c source file. To extract a single file, you specify the full path from the zip file that you want to extract. By default, UNZIP will extract this file using the path provided in the zip file. To omit the path information, you can add the -j ("junk the path") option.

D:\SRC>unzip -j banana.zip banana/putimage.c
Archive:  banana.zip
  inflating: ./putimage.c

Creating and managing zip files is a key skill for any DOS user. You can learn more about ZIP and UNZIP at the Info-ZIP website, or use the -h ("help") option on the command line to print out a list of options.