Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash zip uso: Comprimir archivos y directorios
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
      1. Compressing Files
      2. Compressing a Directory
      3. Encrypting a Zip File
      4. Updating a Zip File
      5. Deleting Files from a Zip Archive
    5. Tips

[Linux] Bash zip uso: Comprimir archivos y directorios

Overview

The zip command is used to compress files and directories into a single archive file, making it easier to store and transfer data. It is widely used for reducing file sizes and grouping multiple files together.

Usage

The basic syntax of the zip command is as follows:

zip [options] [zipfile] [files]
  • [options]: Various options to modify the behavior of the command.
  • [zipfile]: The name of the output zip file.
  • [files]: The files and directories to be included in the zip archive.

Common Options

Here are some common options for the zip command:

  • -r: Recursively include files and directories.
  • -e: Encrypt the zip file with a password.
  • -9: Use the best compression method (maximum compression).
  • -u: Update the zip file with newer versions of files.
  • -d: Delete specified files from the zip archive.

Common Examples

Compressing Files

To create a zip file named archive.zip containing file1.txt and file2.txt:

zip archive.zip file1.txt file2.txt

Compressing a Directory

To compress an entire directory named myfolder into myfolder.zip, use the -r option:

zip -r myfolder.zip myfolder

Encrypting a Zip File

To create an encrypted zip file named secure.zip containing file.txt, use the -e option:

zip -e secure.zip file.txt

Updating a Zip File

To update archive.zip with a newer version of file1.txt:

zip -u archive.zip file1.txt

Deleting Files from a Zip Archive

To remove file2.txt from archive.zip:

zip -d archive.zip file2.txt

Tips

  • Always check the contents of your zip file using unzip -l [zipfile] before sharing it.
  • Use the -9 option for maximum compression, but be aware that it may take longer to create the zip file.
  • Consider using encryption for sensitive files to protect your data when compressing.