Cross-platform file compression
Command Line – zip
If you use file compression regularly, zip belongs in your Linux toolbox.
File compression in Linux is usually handled by the native commands tar
, gzip
, or bzip2
. However, an additional alternative is zip
[1], a popular cross-platform command supported by a variety of scripts and utilities. If you are dealing with someone using another operating system, zip
is often the ideal choice among these compression tools.
Admittedly, on Linux, zip
has fallen out of favor, because for a time it did not support 64-bit computing and could not handle files large than 2MB. Today, though, zip
, gzip
, and bzip2
are broadly similar in functionality and structure. All three have similar options, although not always the same name for every option. All three, too, have a history of providing alternate command names for some functions, such as unzip
and ungzip
, that duplicate standard options – presumably to make the commands easier to remember.
Despite these similarities, neither zip
nor gzip
recognizes the other's extensions, although both can use files created by the other if the extension is changed. zip
can use the option --bzip
to use bzip
options, which can produce somewhat better compression rates, at least in theory, on binary files.
Zip Basics
If you have worked with other compression programs, zip
is easy to start using. The only unusual feature is that a new archive name follows the command and the options and is followed by a space-separated list of the files to archive:
zip OPTIONS NEW-ARCHIVE.zip FILES
Files are not deleted when being added to an archive (Figure 1).
If you choose, the options can include the option --recurse-patterns
(-R
), which automatically includes subdirectories. You can also strike a balance between the speed and efficiency of compression with -NUMBER
, with
indicating no compression, 1
the fastest but least compression, and 9
the slowest but greatest compression. The highest compression is somewhere between 2:1 or 3:1 for text, while binary files are usually considerably less, perhaps 3:2 or 4:3.
However, these options are only the beginning. You can use --exclude
(-x
) to list files that should not go into the archive or --include
(-i
) to specify that only certain files are included. For security, you might also want to add --password
(-P
) STRING
or --encrypt
(-e
), although the security is somewhat weak by modern standards (see zipcloak
below). Still another option is --entry-comments
(-c
), which lets you annotate each file in an archive with a single-line comment that can be read using the zipnote
utility (Figure 2). As the options grow, you are well-advised to add --test
(-T
) to ensure that nothing unexpected happens.
zip
's options really come into their own once an archive is created. You can use --delete
(-d
) or unzip
to remove files from an existing archive and --grow
(-g
) to add files. Alternatively, you can use --copy-entries
(-U
) to create a new archive consisting of files in an existing one. If you are creating archives for backups, you can use --update
(-u
), --filesync
(-FS
), or --freshen
(-f
) to keep the backups current. Should an archive become corrupt, you can try to repair it using --fix
(-F
). However, many of zip
's options require considerably more information. Consequently, the most that I can do in this article is indicate the possibilities.
Zip Utilities
A series of small scripts and utilities have sprouted up around zip
. These utilities' usefulness is sometimes limited by their inability to handle files larger than 2GB. This limitation extends to larger files made with recent versions of zip
, including those created from a desktop environment. However, even with these limitations, the utilities can sometimes be useful, especially if you are working with text files. Some are installed alongside zip
, while one or two have to be installed separately.
zipcmp
Like diff
with text files, zipcmp
compares the files in zip
archives. The command is so simple that it does not include a separate man page or help option. All you need to do is enter the command, followed by the two files to compare. The first file is marked by a minus sign and the second by a plus sign (Figure 3).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.