zipCreate ZIP archives that open everywhere
zip packs and compresses files into a .zip archive in one step. It's the format Windows and macOS open natively, and the one AWS Lambda, browsers and Java (jar, war) expect. Each file is compressed separately, so you can update or delete members in place.
zip [OPTIONS] ARCHIVE.zip FILE... (zip -r for directories)A colleague on Windows needs the app source, without node_modules.
zipInfo-ZIP's zip: creates or updates a .zip archive.
A ZIP file stores each member as a local header (name, method, CRC32, sizes, DOS timestamp) followed by its data, compressed on its own with DEFLATE (or just stored if compression doesn't help). At the very end comes the central directory: a list of every member with the offset of its local header, plus an end-of-central-directory record. Readers start from the end, read the central directory and jump straight to the member they want: random access, which a .tar.gz can't do. Because members are compressed separately, zip can add, replace (-u, -f) or delete (-d) members by rewriting the archive without recompressing the others, but similar files can't share compression context, so the ratio is worse than tar.gz for many small similar files. Unix permissions are kept in the 'external attributes' field; owners are not. zip -e uses the old ZipCrypto scheme, which is easy to break.
-rRecurse into directories-qQuiet-x PATTERNExclude matching files-i PATTERNInclude only matching files-jJunk paths: store files without their directory names-u / -fUpdate changed and add new files / only refresh existing members-dDelete members from an existing archive-0 ... -9Store only ... best compression (default 6)-yStore symlinks as links instead of the files they point to-TTest the archive after writing it-eEncrypt with a password (weak ZipCrypto)zip app.zip appWithout -r only the directory entry is added; the archive is essentially empty.
zip -r app.zip appzip -r function.zip build/ for a Lambda packageFiles end up under build/ inside the zip and Lambda can't find the handler.
cd build && zip -r ../function.zip .Relying on zip -e to protect secretsZipCrypto is broken; known-plaintext attacks recover the key quickly.
gpg -c file, age, or 7z -p with AES-256Using zip to back up a Linux serverzip doesn't store owners, and handles special files and hard links poorly.
tar (with --numeric-owner) or rsyncTry these on a Linux machine of your own. Each task has a hint and a solution.
Create logs.zip from the ~/logs directory, including everything inside it.
Create app.zip from ~/app but leave out every .log file.
Remove one file from app.zip without recreating it, then test the archive.
zipCreate ZIP archives that open everywhere
zip packs and compresses files into a .zip archive in one step. It's the format Windows and macOS open natively, and the one AWS Lambda, browsers and Java (jar, war) expect. Each file is compressed separately, so you can update or delete members in place.
zip [OPTIONS] ARCHIVE.zip FILE... (zip -r for directories)A colleague on Windows needs the app source, without node_modules.
zipInfo-ZIP's zip: creates or updates a .zip archive.
A ZIP file stores each member as a local header (name, method, CRC32, sizes, DOS timestamp) followed by its data, compressed on its own with DEFLATE (or just stored if compression doesn't help). At the very end comes the central directory: a list of every member with the offset of its local header, plus an end-of-central-directory record. Readers start from the end, read the central directory and jump straight to the member they want: random access, which a .tar.gz can't do. Because members are compressed separately, zip can add, replace (-u, -f) or delete (-d) members by rewriting the archive without recompressing the others, but similar files can't share compression context, so the ratio is worse than tar.gz for many small similar files. Unix permissions are kept in the 'external attributes' field; owners are not. zip -e uses the old ZipCrypto scheme, which is easy to break.
-rRecurse into directories-qQuiet-x PATTERNExclude matching files-i PATTERNInclude only matching files-jJunk paths: store files without their directory names-u / -fUpdate changed and add new files / only refresh existing members-dDelete members from an existing archive-0 ... -9Store only ... best compression (default 6)-yStore symlinks as links instead of the files they point to-TTest the archive after writing it-eEncrypt with a password (weak ZipCrypto)zip app.zip appWithout -r only the directory entry is added; the archive is essentially empty.
zip -r app.zip appzip -r function.zip build/ for a Lambda packageFiles end up under build/ inside the zip and Lambda can't find the handler.
cd build && zip -r ../function.zip .Relying on zip -e to protect secretsZipCrypto is broken; known-plaintext attacks recover the key quickly.
gpg -c file, age, or 7z -p with AES-256Using zip to back up a Linux serverzip doesn't store owners, and handles special files and hard links poorly.
tar (with --numeric-owner) or rsyncTry these on a Linux machine of your own. Each task has a hint and a solution.
Create logs.zip from the ~/logs directory, including everything inside it.
Create app.zip from ~/app but leave out every .log file.
Remove one file from app.zip without recreating it, then test the archive.