How to archive files on FreeDOS
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 handy way to make a backup copy of your work, or to release a "package" that can be used in a future FreeDOS distribution. For example, let's say I wanted to make a backup of my project source code, which contains these source files:
C:\SRC>dir myproj
Volume in drive C is FREEDOS
Volume Serial Number is 2269-1AFD
Directory of C:\SRC\MYPROJ
. <DIR> 05-16-2021 11:14p
.. <DIR> 05-16-2021 11:14p
CALENDAR C 5,161 03-18-2021 2:19p
GRDEMO C 8,982 03-18-2021 2:19p
MEMOS C 18,691 03-18-2021 2:19p
MEMOS H 394 03-18-2021 2:19p
PGDEMO C 5,518 03-18-2021 2:19p
PMHELLO C 760 03-18-2021 2:19p
WINHELLO C 567 03-18-2021 2:19p
WSTUB C 3,462 03-18-2021 2:19p
_MATHERR C 948 03-18-2021 2:19p
9 file(s) 44,483 bytes
2 dir(s) 64,868,352 bytes free
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.
C:\SRC>zip -9r bak.zip myproj
adding: myproj/ (stored 0%)
adding: myproj/calendar.c (deflated 73%)
adding: myproj/pmhello.c (deflated 55%)
adding: myproj/_matherr.c (deflated 56%)
adding: myproj/memos.c (deflated 75%)
adding: myproj/winhello.c (deflated 51%)
adding: myproj/wstub.c (deflated 59%)
adding: myproj/pgdemo.c (deflated 74%)
adding: myproj/grdemo.c (deflated 71%)
adding: myproj/memos.h (deflated 55%)
C:\SRC>dir bak.zip
Volume in drive C is FREEDOS
Volume Serial Number is 2269-1AFD
Directory of C:\SRC
BAK ZIP 14,010 05-16-2021 11:19p
1 file(s) 14,010 bytes
0 dir(s) 64,854,016 bytes free
In my example, ZIP was able to compress my source files from about 44 kilobytes down to about 14 kilobytes, saving me valuable disk space. You might get different compression ratios depending on what options you give to ZIP or what files (and how many) you are trying to store in a Zip file. Generally, very long text files (such as source code) yield good compression; very small text files (like DOS "batch" files of only a few lines) are usually too short to compress well.
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:
C:\SRC>unzip -l bak.zip
Archive: bak.zip
Length Date Time Name
--------- ---------- ----- ----
0 05-16-2021 23:14 myproj/
5161 03-18-2021 14:19 myproj/calendar.c
760 03-18-2021 14:19 myproj/pmhello.c
948 03-18-2021 14:19 myproj/_matherr.c
18691 03-18-2021 14:19 myproj/memos.c
567 03-18-2021 14:19 myproj/winhello.c
3462 03-18-2021 14:19 myproj/wstub.c
5518 03-18-2021 14:19 myproj/pgdemo.c
8982 03-18-2021 14:19 myproj/grdemo.c
394 03-18-2021 14:19 myproj/memos.h
--------- -------
44483 10 files
The output allows me to to see the 10 entries in the Zip file: 9 files plus the myproj 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 will extract the Zip file starting at my current working dirctory. 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:
C:\SRC>unzip bak.zip -d temp
Archive: bak.zip
creating: temp/myproj/
inflating: temp/myproj/calendar.c
inflating: temp/myproj/pmhello.c
inflating: temp/myproj/_matherr.c
inflating: temp/myproj/memos.c
inflating: temp/myproj/winhello.c
inflating: temp/myproj/wstub.c
inflating: temp/myproj/pgdemo.c
inflating: temp/myproj/grdemo.c
inflating: temp/myproj/memos.h
Sometimes I want to extract a single file from a Zip file. In this example, let's say I wanted to extract just the calendar.c 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.
You can also combine options. Let's extract the myproj/calendar.c source file from the Zip archive, but omit the full path, and save it in the NEW directory:
C:\SRC>unzip -j bak.zip myproj/calendar.c -d new
Archive: bak.zip
inflating: new/calendar.c
Because Zip files are an open standard, we continue to see Zip files today. Every Linux distribution supports Zip files using the Info-ZIP programs. Your Linux file manager may also have Zip file support; on the GNOME file manager, you should be able to right-click on a folder and select "Compress" from the drop-down menu. You'll have the option to create a new archive file, including a Zip file.
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.