Some of us have been zipping files on Unix and Linux systems for many decades \u2014 to save some disk space and package files together for archiving. Even so, there are some interesting variations on zipping that not all of us have tried. So, in this post, we\u2019re going to look at standard zipping and unzipping as well as some other interesting zipping options.\n\nThe basic zip command\nFirst, let\u2019s look at the basic zip command. It uses what is essentially the same compression algorithm as gzip, but there are a couple important differences. For one thing, the gzip command is used only for compressing a single file where zip can both compress files and join them together into an archive. For another, the gzip command zips \u201cin place\u201d. In other words, it leaves a compressed file \u2014 not the original file alongside the compressed copy. Here's an example of gzip at work:\n$ gzip onefile\n$ ls -l\n-rw-rw-r-- 1 shs shs 10514 Jan 15 13:13 onefile.gz\n\nAnd here's zip. Notice how this command requires that a name be provided for the zipped archive where gzip simply uses the original file name and adds the .gz extension.\n$ zip twofiles.zip file*\n adding: file1 (deflated 82%)\n adding: file2 (deflated 82%)\n$ ls -l\n-rw-rw-r-- 1 shs shs 58021 Jan 15 13:25 file1\n-rw-rw-r-- 1 shs shs 58933 Jan 15 13:34 file2\n-rw-rw-r-- 1 shs shs 21289 Jan 15 13:35 twofiles.zip\n\nNotice also that the original files are still sitting there.\nThe amount of disk space that is saved (i.e., the degree of compression obtained) will depend on the content of each file. The variation in the example below is considerable.\n$ zip mybin.zip ~\/bin\/*\n adding: bin\/1 (deflated 26%)\n adding: bin\/append (deflated 64%)\n adding: bin\/BoD_meeting (deflated 18%)\n adding: bin\/cpuhog1 (deflated 14%)\n adding: bin\/cpuhog2 (stored 0%)\n adding: bin\/ff (deflated 32%)\n adding: bin\/file.0 (deflated 1%)\n adding: bin\/loop (deflated 14%)\n adding: bin\/notes (deflated 23%)\n adding: bin\/patterns (stored 0%)\n adding: bin\/runme (stored 0%)\n adding: bin\/tryme (deflated 13%)\n adding: bin\/tt (deflated 6%)\n\nThe unzip command\nThe unzip command will recover the contents from a zip file and, as you'd likely suspect, leave the zip file intact, whereas a similar gunzip command would leave only the uncompressed file.\n$ unzip twofiles.zip\nArchive: twofiles.zip\n inflating: file1\n inflating: file2\n$ ls -l\n-rw-rw-r-- 1 shs shs 58021 Jan 15 13:25 file1\n-rw-rw-r-- 1 shs shs 58933 Jan 15 13:34 file2\n-rw-rw-r-- 1 shs shs 21289 Jan 15 13:35 twofiles.zip\n\nThe zipcloak command\nThe zipcloak command encrypts a zip file, prompting you to enter a password twice (to help ensure you don't "fat finger" it) and leaves the file in place. You can expect the file size to vary a little from the original.\n$ zipcloak twofiles.zip\nEnter password:\nVerify password:\nencrypting: file1\nencrypting: file2\n$ ls -l\ntotal 204\n-rw-rw-r-- 1 shs shs 58021 Jan 15 13:25 file1\n-rw-rw-r-- 1 shs shs 58933 Jan 15 13:34 file2\n-rw-rw-r-- 1 shs shs 21313 Jan 15 13:46 twofiles.zip comments\n\nNext, edit the file you've just created, inserting your comments above the (comment above this line) lines. Then add the comments using a zipnote command like this one:\n$ zipnote -w twofiles.zip < comments\n\nThe zipsplit command\nThe zipsplit command can be used to break a zip archive into multiple zip archives when the original file is too large \u2014 maybe because you're trying to add one of the files to a small thumb drive. The easiest way to do this seems to be to specify the max size for each of the zipped file portions. This size must be large enough to accomodate the largest included file.\n$ zipsplit -n 12000 twofiles.zip\n2 zip files will be made (100% efficiency)\ncreating: twofile1.zip\ncreating: twofile2.zip\n$ ls twofile*.zip\n-rw-rw-r-- 1 shs shs 10697 Jan 15 14:52 twofile1.zip\n-rw-rw-r-- 1 shs shs 10702 Jan 15 14:52 twofile2.zip\n-rw-rw-r-- 1 shs shs 21377 Jan 15 14:27 twofiles.zip\n\nNotice how the extracted files are sequentially named "twofile1" and "twofile2".\nWrap-up\nThe zip command, along with some of its zipping compatriots, provide a lot of control over how you generate and work with compressed file archives.