Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

zip, unzip

Pack files into a .zip archive (zip) and unpack it (unzip) — the format that Windows and macOS open directly.

Niveau
Dagelijks Linux
Groep
Archiveren en comprimeren
Root nodig
Nee
Pakket
zip, unzip
Ook
unzip

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

zip makes one archive with many files and folders, compressed. unzip extracts it. Use zip when you exchange files with Windows users or upload to tools that want .zip.

For Linux backups, tar is better: zip does not keep Linux owners and some permissions the same way.

Zo schrijf je het

zip [OPTIONS] ARCHIVE.zip FILE...
unzip [OPTIONS] ARCHIVE.zip [FILE...] [-x EXCLUDE...] [-d DIR]

Opties 50

Meest gebruikt

zip

-r
Include folders and everything in them (recursive).
-q
Quiet: no messages.
-v
Verbose output.
-0 ... -9
Compression level: 0 = store only, 9 = best. Default 6.
-e
Encrypt the files; zip asks for a password.
-P password
Give the password on the command line (unsafe: it is in the history).
-x patterns
Leave out files that match.
-i patterns
Include only files that match.
-u
Update: add new files and replace changed files in the archive.
-f
Freshen: replace changed files only (do not add new ones).
-m
Move: delete the original files after zipping.
-d
Delete files from the archive.
-j
Junk paths: store only file names, no folders.
-y
Store symbolic links as links (not the files they point to).
-T
Test the new archive after writing it.
-s size
Split the archive into parts of this size (like 100m).
-l, -ll
Convert line endings (LF to CRLF / CRLF to LF) for text files.
-o
Set the archive time to the newest file's time.
-z
Add a comment to the archive.
-c
Add a one-line comment for each file.
-@
Read the file names from standard input.
-D
Do not add separate entries for folders.
-n suffixes
Do not compress files with these endings (like .jpg:.png).
-b path
Folder for the temporary file.
-X
Do not save extra file attributes (Unix UID/GID, times).
-F, -FF
Try to fix a damaged archive.
-A
Fix the offsets of a self-extracting archive.
-g
Grow (add to) an existing archive.
-t date, -tt date
Only files changed on or after / before this date.
-S
Include system and hidden files (on MS-DOS/Windows).
-h, -h2
Show help (-h2 = extended help).

unzip

-l
List the files in the archive (short).
-v
List with details (verbose).
-t
Test the archive.
-d dir
Extract into this folder.
-o
Overwrite existing files without asking.
-n
Never overwrite existing files.
-q
Quiet.
-j
Junk paths: extract all files into one folder.
-x files
Do not extract these files.
-p
Extract to stdout (pipe) without messages.
-c
Extract to the screen with the file names.
-f
Freshen: extract only files that already exist and are newer in the archive.
-u
Update: extract new files and newer versions of existing files.
-P password
The password for encrypted archives (unsafe on the command line).
-a
Convert text files to the local line endings.
-L
Make names lowercase.
-C
Match names without upper/lower case.
-z
Show only the archive comment.
-Z
Work like zipinfo (detailed listing).

Voorbeelden 12

$ als gewone gebruiker# als root (of met sudo)

  1. 1Zip a folder

    zip -r report.zip report/

    -r takes the whole folder.

  2. 2Unzip into a folder

    unzip report.zip -d /tmp/report

    The folder is made if it does not exist.

  3. 3List the content before you extract

    unzip -l upload.zip

    Check for strange paths like ../ before you trust a zip from outside.

  4. 4Zip with a password

    zip -e -r secret.zip contracts/

    zip asks for the password. Note: classic zip encryption is weak; use 7z or gpg for real secrets.

  5. 5Leave out files

    zip -r site.zip public_html -x '*.log' '*/.git/*'

    Smaller archive, no logs, no git data.

  6. 6Add or update files in an archive

    zip -u site.zip public_html/index.html

    Only changed files are replaced.

  7. 7Extract only one file

    unzip site.zip public_html/index.html -d /tmp

    Give the path as it is stored in the archive.

  8. 8Test an archive

    unzip -t backup.zip

    "No errors detected" means the file is complete.

  9. 9Overwrite without questions in a script

    unzip -o -q release.zip -d /srv/app

    -o overwrites, -q keeps the log clean.

  10. 10Store files without folders

    zip -j logs.zip /var/log/httpd/*.log

    All files at the top level of the zip.

  11. 11Split a big archive for upload limits

    zip -r -s 100m dataset.zip dataset/

    Makes dataset.z01, dataset.z02 … and dataset.zip.

  12. 12Make a zip from a list of files

    find . -name "*.pdf" | zip invoices.zip -@

    The names come from find.

Let op

  • Check the content of an unknown zip with unzip -l before you extract (path tricks, very large "zip bombs").
  • -P password is saved in the shell history; use -e so it is asked.
  • zip does not keep Linux owners on extract; use tar for system backups.

Tips om te onthouden

  • Pack: zip -r name.zip folder. Unpack: unzip name.zip -d folder. Look: unzip -l.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man zip