Skip to main content

Zip Command

On Linux, the zip command is used to package and compress (archive) files. Here are some basic usages of the zip command:

  1. Compress files into zip format:

    zip archive_name.zip file1 file2 file3

    Here, archive_name.zip is the name of the zip file you want to create, and file1, file2, and file3 are the files you want to compress.

  2. Compress an entire directory into zip format:

    zip -r archive_name.zip directory_name

    The -r flag means recursive processing, compressing all files and subdirectories under the specified directory into the zip file.

  3. Compress specific file types using wildcards:

    zip archive_name.zip *.txt

    This command compresses all files with the .txt extension into archive_name.zip.

  4. Compress files into zip format with encryption:

    zip -e encrypted_archive.zip file1 file2

    The -e flag encrypts the compressed file. After running this command, the system will prompt you to enter a password.

  5. Exclude specific files or directories:

    zip -r archive_name.zip folder_to_zip -x file_to_exclude \*.log

    The -x flag specifies files or patterns to exclude. The above command compresses the folder_to_zip directory but excludes all .log files and file_to_exclude.

  6. View the contents of a zip file:

    zip -sf archive_name.zip

    The -sf flag displays the file list inside the zip file without extracting it.

  7. Extract specific files from a zip file:

    unzip archive_name.zip file_to_extract

    This command only extracts file_to_extract from archive_name.zip.

  8. Extract a zip file to a specified directory:

    unzip archive_name.zip -d destination_directory

    The -d flag specifies the destination directory for extraction.

These are the basic usages of the zip command. The zip command has many other options and parameters. You can view more detailed help by entering man zip in the terminal.