Skip to content

zip Linux command

The Linux zip command is used to compress and archive files in a zip format. It allows users to save disk space, make file transfer easier, and keep related files together. This command provides various options for customization, such as adding passwords to protect the zip file or specifying compression levels. By using the zip command, users can efficiently manage and organize their files and directories.

zip Syntax:

Terminal window
zip [options] [target.zip] [source_files/directories]

Options:

OptionDescription
-rRecursively zip subdirectories
-qQuiet mode (no output)
-jJunk the paths
-uUpdate existing zip file
-vVerbose mode
-mMove files (delete originals)
-dDelete files from zip file
-yStore symbolic links as such
-1Compress faster
-9Best compression
-hHelp and usage information

Parameters:

ParameterDescription
target.zipName of the target zip file to create
source_filesFiles to be zipped
source_directoriesDirectories to be recursively zipped

zip bash Examples:

Compress a Single File

Terminal window
zip compressed_file.zip file.txt

Compresses a single file named “file.txt” into a zip archive named “compressed_file.zip”.

Compress Multiple Files

Terminal window
zip compressed_files.zip file1.txt file2.txt file3.txt

Compresses multiple files (“file1.txt”, “file2.txt”, and “file3.txt”) into a zip archive named “compressed_files.zip”.

Compress a Directory

Terminal window
zip -r compressed_directory.zip directory/

Recursively compresses a directory named “directory” and its contents into a zip archive named “compressed_directory.zip”.

Password Protect a Zip Archive

Terminal window
zip -P password secure_file.zip file.txt

Compresses a single file named “file.txt” into a password-protected zip archive named “secure_file.zip” with the password “password”.

Exclude Files from Compression

Terminal window
zip -r compressed_folder.zip folder/ -x "*.log"

Compresses a directory named “folder” and its contents into a zip archive named “compressed_folder.zip”, excluding all files with the .log extension.

View Zip Archive Contents

Terminal window
unzip -l compressed_file.zip

Lists the contents of a zip archive named “compressed_file.zip” without extracting the files.

zip Command Help Center:

How do I use zip in Linux?

To use the zip command in Linux, execute the following command:

Terminal window
zip --option <value>

How can I create a zip file in Linux?

To create a zip file in Linux, use the following command:

Terminal window
zip -r archive.zip /path/to/directory

How do I compress specific files with zip in Linux?

To compress specific files with zip in Linux, use the following command:

Terminal window
zip archive.zip file1.txt file2.txt

How can I add a password to a zip file in Linux?

To add a password to a zip file in Linux, use the following command:

Terminal window
zip --encrypt archive.zip file.txt

How do I unzip a file in Linux with zip?

To unzip a file in Linux using zip, use the following command:

Terminal window
unzip archive.zip

How can I overwrite an existing zip file in Linux?

To overwrite an existing zip file in Linux, use the following command:

Terminal window
zip -f archive.zip file.txt

How do I list the contents of a zip file in Linux?

To list the contents of a zip file in Linux, use the following command:

Terminal window
unzip -l archive.zip

How can I update a zip file in Linux?

To update a zip file in Linux, use the following command:

Terminal window
zip -u archive.zip newfile.txt

Applications of the zip command

  • Creating a compressed archive of one or multiple files
  • Compressing files to reduce storage space
  • Bundling multiple files into a single archive for easier sharing and distribution
  • Creating backups of files or directories in a compressed format
  • Password protecting the compressed archive for security purposes