Creating compressed archives in Linux streamlines backups, sharing, and deployment by packing multiple items into a single file. Using the zip format keeps archives compatible with Windows, macOS, and Linux, which simplifies collaboration and transfer across heterogeneous environments.
The zip utility reads a list of files and directories from the command line and writes a compressed archive using the Deflate algorithm by default. File names, directory structure, and timestamps are stored inside the archive so that unpacking reconstructs the layout relative to the extraction directory.
Archive creation does not modify the original files, but command choices still affect which paths are captured, how deep directory recursion goes, and where the resulting .zip file is written. Clear paths, careful use of options such as -r, and quick verification with listing commands reduce the risk of missing or unintended content in the final archive.
$ echo $SHELL /bin/bash
$ cd /root/sg-work/zip-demo $ ls file1.txt file2.txt folder1 folder2 report.txt
Commands operate on paths relative to the current working directory unless absolute paths are used.
$ zip report.zip report.txt adding: report.txt (stored 0%)
Archive file report.zip is created in the current directory if it does not already exist.
$ zip archive.zip file1.txt file2.txt folder1/ adding: file1.txt (stored 0%) adding: file2.txt (stored 0%) adding: folder1/ (stored 0%)
Any directory arguments cause contained files to be added relative to that directory name.
$ zip -r project-backup.zip folder2/ adding: folder2/ (stored 0%) adding: folder2/src/ (stored 0%) adding: folder2/src/main.c (stored 0%) adding: folder2/docs/ (stored 0%) adding: folder2/docs/readme.md (stored 0%)
Option -r walks subdirectories so every file under folder2 is stored in the archive.
$ zip -r logs-archive.zip folder1/ -x "*.tmp" "*.bak" adding: folder1/ (stored 0%) adding: folder1/app.log (stored 0%) adding: folder1/note.txt (stored 0%)
Option -x filters out paths that match the given patterns, which prevents unnecessary files from inflating archive size.
$ ls -lh total 36K -rw-r--r-- 1 root root 466 Jan 11 05:16 archive.zip -rw-r--r-- 1 root root 4 Jan 11 05:09 file1.txt -rw-r--r-- 1 root root 4 Jan 11 05:09 file2.txt drwxr-xr-x 2 root root 4.0K Jan 11 05:09 folder1 drwxr-xr-x 4 root root 4.0K Jan 11 05:09 folder2 -rw-r--r-- 1 root root 493 Jan 11 05:16 logs-archive.zip -rw-r--r-- 1 root root 838 Jan 11 05:16 project-backup.zip -rw-r--r-- 1 root root 7 Jan 11 05:09 report.txt -rw-r--r-- 1 root root 177 Jan 11 05:16 report.zip
File size depends on the original data and how well it compresses; some binary formats may show little reduction.
$ unzip -l project-backup.zip
Archive: project-backup.zip
Length Date Time Name
--------- ---------- ----- ----
0 2026-01-11 05:09 folder2/
0 2026-01-11 05:09 folder2/docs/
7 2026-01-11 05:09 folder2/docs/readme.md
0 2026-01-11 05:09 folder2/src/
23 2026-01-11 05:09 folder2/src/main.c
--------- -------
30 5 files
Listing output confirms which files are stored in the archive and how they are laid out inside the directory structure.