Session and utilities
The zip command
Creates .zip archives, the format most compatible with Windows, macOS and almost any program. It compresses each file separately and can add or remove entries from an existing zip.
Most useful options
-rGoes into folders and adds all their contents. Without -r, it only adds the folder entry, empty-jStores only each file name, without the folder path-eEncrypts the contents and asks for the password. Careful: the encryption is weak (see security)-9Maximum compression: slower, and the file comes out a little smaller-x <patrón>Excludes the files matching the pattern. Put it in quotes-uUpdate: adds only new files or files changed since last timeCopy-ready examples
$ zip -r proyecto.zip proyecto/packs the whole folder, with subfolders, and lists each entry.Example output
adding: proyecto/ (stored 0%) adding: proyecto/main.py (deflated 42%) adding: proyecto/README.md (deflated 31%)
$ zip -e secreto.zip contrato.pdfencrypts the PDF with a password. Read the security section first.$ zip -j fotos.zip vacaciones/*.jpggathers the photos into a flat zip, without the source folders.$ zip -9 -r respaldo.zip Documentos -x '*.tmp'maximum compression and without the .tmp temporary files.$ zip -u proyecto.zip main.pyreplaces only main.py in the zip, if it has changed.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| zip warning: name not matched: nofile | The name does not exist in the current folder. zip warns and carries on with the other names. | Check the names with ls before compressing. |
| zip error: Nothing to do! (backup.zip) | No file could be added: all the names were wrong. zip exits with code 12 and does not create the archive. | Fix the names or the path and run the command again. |
Typical mistakes
- Without -r, zip does not go into folders: the zip ends up with an empty folder entry and nothing inside.
- If the zip already exists, zip adds or updates entries inside it instead of creating it from scratch.
Differences from similar commands
Security
zip -e uses ZipCrypto by default, a weak cipher that common tools can break. For real data, use gpg or 7z with AES-256.
FAQ
zip or tar.gz?
To share with Windows or macOS, zip. For Linux backups that need permissions and links, tar. Both do most other jobs.
Why is no zip created?
If no file could be added, zip warns with name not matched and creates nothing, exiting with code 12. Check the names.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course