GICT knowledge base
ZIP and Unzip on Linux: Create, Test and Extract Safely
Published
Use zip to create a ZIP archive and unzip to inspect or extract it. Install maintained packages from your supported distribution if the commands are missing; a broad operating-system upgrade is not a prerequisite for practicing this task. Check the installed manuals because options vary by implementation.
Create a ZIP including dotfiles
This fixture uses a new private directory and contains no live website data. Run all blocks in the same Bash session.
umask 077
lab=$(mktemp -d)
cd "$lab" || exit 1
mkdir -p source/cache
printf 'page\n' > source/index.html
printf 'setting=yes\n' > source/.settings
printf 'temporary\n' > source/cache/item.txt
zip -r site.zip source -x 'source/cache/*'
unzip -l site.zip
unzip -t site.zip
The explicit directory operand includes hidden files. A command ending in * commonly misses them. Write the archive outside the source tree. -r recurses; exclusions must match the names stored in the ZIP. A test checks archive structure/data integrity, not whether every required website file or database was captured.
Extract without overwriting a live site
mkdir restore
unzip site.zip -d restore
cmp source/index.html restore/source/index.html
cmp source/.settings restore/source/.settings
-d selects the destination directory; it does not select which member to extract. The stored source/ prefix remains in the restored path. Inspect paths, symlinks and expanded sizes first; use a fresh unprivileged destination for trusted archives, and stronger isolation for untrusted content. Do not extract as root over system or website files.
To extract one named member into another fresh directory:
mkdir selected
unzip site.zip 'source/index.html' -d selected
cmp source/index.html selected/source/index.html
Update or remove members deliberately
Adding files to an existing named ZIP updates that archive. Work on a copy before modifying a recovery artifact. In Info-ZIP, zip -d deletes matching members; this is different from unzip -d. Confirm exact names with unzip -l. Avoid unattended overwrite flags unless a verified destination and rollback plan make them appropriate.
Password protection and recovery limits
Traditional Info-ZIP encryption is weak and unsuitable protection for sensitive backups. Do not publish passwords on a command line, in shell history or in a web-accessible script. Use an approved modern encrypted backup/archive workflow with separately protected recovery material and compatible recipient tools. Compression is not encryption.
A website may require database exports, private configuration, uploads, permissions and external service settings beyond the ZIP. Verify a recovery in isolation before replacing newer live content. Keep backups outside the public document root and outside the server’s failure domain.
References: Info-ZIP FAQ and encryption limitations and archive security considerations.
Reviewed October 15, 2026. The three practice blocks were executed on synthetic files with Info-ZIP tools in a disposable container; no full website restore was tested.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
