--- title: zip โ€” Create Compressed Archive date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A command that bundles multiple files into a zip archive. Especially useful when exchanging files with Windows. tags: program, File and disk management, zip --- **๐Ÿ’ฌ "zip command"** zip is an archive format that opens directly on Windows too. It is especially convenient for transferring files between Linux and Windows. When including directories, you must add `-r`. - **Concept**: bundles files and directories into zip format. - **Left argument**: the name of the archive file to create. - **Right argument**: the list of files/directories to compress. - **Progress display**: by default, prints the compression ratio for each file. ## Commonly used options | Option | Description | | --- | --- | | -r | recursively include directories โ€” required | | -q | run quietly without progress output | | -x '*.log' | exclude specific patterns | | -e | encrypt with a password | | -9 | compress with maximum compression ratio | ## Three essential command combinations - `zip -r site-20261018.zip /var/www/html` โ€” bundle the web root into a zip - `zip -rq release.zip . -x '*.log' -x 'cache/*'` โ€” bundle quietly, excluding logs and cache - `zip -r9 arch.zip src/ docs/ README.md` โ€” bundle artifacts with maximum compression **๐Ÿ’ฌ "How would you use it in an automation script?"** Here are common production server situations, organized in order. ### Step 1 ยท Identify what to archive Move to the target directory or specify an absolute path. ``` cd /var/www && ls html ``` ### Step 2 ยท Compress Use the recursive option to archive and specify exclusion patterns. ``` zip -rq /tmp/site-20261018.zip html -x '*.log' ``` ### Step 3 ยท Verify Check the listing and integrity. ``` unzip -l /tmp/site-20261018.zip | tail -2 ``` ## In practice, use it like this ### 1. Delivering to a Windows user **Situation** โ€” the client company cannot open Linux archives (tgz), so zip is needed. ``` zip -r delivery-20261018.zip report/ data.xlsx ``` **Result** โ€” it creates a zip that can be opened directly on Windows. **Point** โ€” Korean filenames can cause encoding issues, so check whether to use the default instead of -UN=UTF8. ### 2. Partial backup **Situation** โ€” you want to back up only the uploads folder as zip. ``` zip -rq /backup/uploads-20261018.zip /var/www/html/uploads ``` **Result** โ€” an archive containing only upload files is created. **Point** โ€” for large amounts of data, tar+gzip is often faster. Use zip only when you need compatibility. ## Caution - If you omit -r, the directory is stored empty (the most common mistake). - zip does not fully preserve permission/owner information. Use tar for server recovery. - Encryption (-e) can be weak, so use a separate encryption tool for sensitive information. ## Actual output This is the result of checking the archive file list and size. ![zip command execution result: archive file list and size](https://games.aidebatehub.com/assets/zip-demo.png) Production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/zip.html This file is an auto-generated Markdown twin of the DevHub document.