zip - Linux


The zip command in Linux is used for file compression and archiving. It condenses and combines multiple files into a single compressed file, known as a zip archive. This utility is particularly useful for saving storage space, managing files efficiently, and facilitating easy file transfers between computers and networks.


The basic syntax of the zip command is:

zip [options] [zipfile] [file1] [file2] ...
  • zipfile: The name of the archive to create.
  • file1, file2, …, filen: The files or directories to include in the zip archive.


Key Options

  • -r: Recursively include directories.
  • -u: Update existing entries and add new files if they don’t exist in the zip archive.
  • -m: Move the specified files into the archive (deletes the original files after making the archive).
  • -f: Fix the corrupted archive if feasible.
  • -d: Delete entries from a zip archive.
  • -l: Convert LF to CR LF (useful when transferring files between Unix-based and DOS-based systems).
  • -v: Verbose mode, which shows the progress of files being zipped.

Example Usage of Flags

  • -r: Commonly used when directories need to be included in the zip archive.


  1. Basic Zip:

    zip file1.txt file2.txt

    This creates a zip archive consisting of file1.txt and file2.txt.

  2. Recursive Zip:

    zip -r directory_name/

    This compresses the entire directory directory_name recursively into

  3. Updating an Archive:

    zip -u new_file.txt

    Updates the zip archive with new_file.txt, only if it is newer than the version in the archive or does not exist.

  4. Delete From Archive:

    zip -d file_to_remove.txt

    Removes file_to_remove.txt from

Common Issues

  • Large File Size: The zip command might not effectively compress highly compressed formats like JPG or MP4. In such cases, the archive might not save substantial space.
  • Permissions: Running zip without adequate file permissions can lead to access denied errors. Ensure proper permissions or run with sudo if necessary.


The zip command can be combined with other commands to facilitate batch processes. For example:

find . -type f -name "*.txt" | xargs zip

This command finds all .txt files in the current directory and subdirectories and adds them to

  • unzip: Used for extracting and viewing files in a ZIP archive.
  • gzip: Compresses or expands files (uses .gz extension).
  • tar: Archive utility often used in combination with compression.

For more comprehensive details, the official zip manual (man zip) provides in-depth usage, flags, and examples.