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
unzip
Niets past bij dit filter.
Voorbeelden 12
$ als gewone gebruiker# als root (of met sudo)
1Zip a folder
zip -r report.zip report/-rtakes the whole folder.2Unzip into a folder
unzip report.zip -d /tmp/reportThe folder is made if it does not exist.
3List the content before you extract
unzip -l upload.zipCheck for strange paths like
../before you trust a zip from outside.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.
5Leave out files
zip -r site.zip public_html -x '*.log' '*/.git/*'Smaller archive, no logs, no git data.
6Add or update files in an archive
zip -u site.zip public_html/index.htmlOnly changed files are replaced.
7Extract only one file
unzip site.zip public_html/index.html -d /tmpGive the path as it is stored in the archive.
8Test an archive
unzip -t backup.zip"No errors detected" means the file is complete.
9Overwrite without questions in a script
unzip -o -q release.zip -d /srv/app-ooverwrites,-qkeeps the log clean.10Store files without folders
zip -j logs.zip /var/log/httpd/*.logAll files at the top level of the zip.
11Split a big archive for upload limits
zip -r -s 100m dataset.zip dataset/Makes dataset.z01, dataset.z02 … and dataset.zip.
12Make a zip from a list of files
find . -name "*.pdf" | zip invoices.zip -@The names come from find.
Niets past bij dit filter.
Let op
- Check the content of an unknown zip with
unzip -lbefore you extract (path tricks, very large "zip bombs"). -P passwordis saved in the shell history; use-eso 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.