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.

Terminal window
zip [options] [target.zip] [source_files/directories]
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
ParameterDescription
target.zipName of the target zip file to create
source_filesFiles to be zipped
source_directoriesDirectories to be recursively zipped
Terminal window
zip compressed_file.zip file.txt

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

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”.

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”.

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”.

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.

Terminal window
unzip -l compressed_file.zip

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

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

Terminal window
zip --option <value>

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?

Section titled “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?

Section titled “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

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?

Section titled “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?

Section titled “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

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

Terminal window
zip -u archive.zip newfile.txt
  • 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