Skip to content
Aback ZIP

How-to · 7 min read · Updated

Zip and unzip from the Linux command line

Use zip, unzip and tar on the Linux command line: create archives, list contents, extract selected files, handle Unicode names and know when a browser helps.

The zip and unzip utilities are available on nearly every Linux distribution, and they are fast, scriptable and predictable. This guide covers the commands you will actually use: packing a folder, listing an archive without extracting it, pulling out one file, and dealing with Unicode names. It also explains where the command line stops, in particular with AES encryption and Deflate64, and when Create ZIP or Extract ZIP is the easier choice. The format itself is specified in PKWARE's ZIP APPNOTE.

Install the tools

Most desktops already have both commands. Check with zip -v and unzip -v. If they are missing, install the packages with your distribution's manager. On Debian and Ubuntu use sudo apt install zip unzip; on Fedora use sudo dnf install zip unzip; on Arch use sudo pacman -S zip unzip. The two programs come from the Info-ZIP project and are separate packages, so it is possible to have one without the other.

If you only need to unpack an archive and do not want to install anything, Extract ZIP opens ZIP, TAR, TAR.GZ and GZ files in the browser and reads them locally.

Create a ZIP archive

The basic form is zip followed by the archive name and the files to include. Add -r to recurse into directories, which is what you want for a whole folder:

zip -r project.zip project/

The trailing slash and folder name mean the archive contains project/ as its top level. To zip the contents of a directory without that parent folder, change into it first and use a wildcard:

cd project && zip -r ../project.zip .
  • -0 stores files without compression, which is faster and sensible for JPEG, PNG, MP4, MP3 and PDF content that is already compressed.
  • -9 asks Deflate to work hardest. On text it saves a little more; on media it changes almost nothing.
  • -x '*.tmp' excludes files matching a pattern. Quote the pattern so the shell does not expand it first.
  • -q quiets the output, useful inside scripts.
  • -@ reads file names from standard input, which lets you build a list with find and pipe it in.

By default Info-ZIP writes UTF-8 names when the source names contain non-ASCII characters. If you need to force a particular interpretation for compatibility with older tools, the -UN option controls how names are encoded. For files created on Windows in a regional code page, Fix ZIP Filenames detects the original encoding and rewrites the names as UTF-8.

List and inspect a ZIP

Use unzip -l to list entries with their sizes and dates, or zipinfo -l for a denser table that includes compression methods:

unzip -l project.zip
zipinfo -l project.zip

Listing reads the central directory at the end of the file and does not decompress anything. That is why it is quick even for archives with many thousands of files. The same idea powers ZIP Viewer, which shows a folder tree, sizes, compression ratios, CRC-32 values and encryption flags without unpacking. If you want to look from a phone or a machine without the utilities installed, that browser route is the convenient one.

  • -Z (or zipinfo) prints one line per file with method, size and timestamp.
  • -t tests each file's CRC without writing anything to disk, the command-line equivalent of Test ZIP Integrity.
  • -Z -1 gives a compact listing with just file names.

Extract files

  1. Extract everything into the current directory with unzip project.zip. Add -d to choose a destination: unzip project.zip -d out/.
  2. To replace existing files without being asked, add -o; to extract only files newer than the local copies, add -u.
  3. For one file or a pattern, pass the name after the archive: unzip project.zip 'docs/*.md' -d out/. Quote the pattern so the shell leaves it for unzip.
  4. To see what would happen without writing anything, use unzip -l first. This matters for archives from unknown sources, where a long path or an unexpected executable is worth noticing.
  5. If the extraction reports a CRC error, the archive or the stored file is damaged. Use unzip -t to find which entries fail, then get a fresh copy or try Repair ZIP.

Be careful with archives from strangers. A malicious entry can try to write outside the destination with ../ paths. Info-ZIP sanitises these, but scripts that pipe names to other tools should validate paths themselves. Aback ZIP's extractors sanitise entry paths too.

Password-protected archives

Info-ZIP's -P and -e options create ZipCrypto-protected archives, and unzip -P password can open them. ZipCrypto is old and weak: it should not be used for anything sensitive. AES-protected ZIPs use a different scheme that Info-ZIP's unzip cannot read at all.

zip -e -P 'a-strong-password' secrets.zip notes.txt
unzip -P 'a-strong-password' secrets.zip

Put a space before the command so the password is not saved in your shell history, or omit -P and let -e prompt you. On the command line the password is often visible in the process list, so a browser tool can be safer: Password Protect ZIP adds AES-256 with the password typed into the page, and Extract ZIP opens AES and ZipCrypto archives when you know the password. Neither guesses passwords; a lost password cannot be recovered by Aback ZIP.

ZIP versus TAR on Linux

Linux software is usually distributed as .tar.gz or .tgz, not ZIP. TAR stores files and Unix attributes such as permissions and symlinks, and GZIP compresses the resulting stream. ZIP is better when the recipients use Windows or macOS and just want a folder. The difference is explained in ZIP vs TAR, and developers often choose one per job.

tar -czf project.tar.gz project/     # create
tar -tzf project.tar.gz              # list
tar -xzf project.tar.gz -C out/      # extract

Swap z for j for bzip2 or J for xz as appropriate; modern GNU tar also detects the compression automatically on extraction. If you need to hand a TAR archive to Windows users, Convert TAR.GZ to ZIP produces a standard ZIP while keeping folders and timestamps. Going the other way, ZIP to TAR writes an archive for Linux workflows.

Quick command reference

TaskCommandNote
Zip a folderzip -r out.zip folder/Keep the folder as the top level
Zip without compressionzip -r -0 out.zip folder/Good for media and PDFs
List contentsunzip -l out.zipReads the index only
Test integrityunzip -t out.zipChecks CRC-32 of every entry
Extract to a folderunzip out.zip -d out/Creates the destination if needed
Extract one fileunzip out.zip 'docs/readme.md'Quote wildcard patterns
Make a tar.gztar -czf out.tar.gz folder/Preserves Unix permissions

Tools for this

Frequently asked questions

Run zip -r archive.zip folder/. The -r includes subfolders, and the folder name becomes the top level inside the archive. Add -0 if the contents are already compressed.

More guides