Linux zip Command
The Linux zip command is used to compress files.
zip is a widely used compression program, and the compressed files have a .zip
suffix.
Syntax
zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][-b <working directory>][-ll][-n <suffix string>][-t <date time>][-<compression efficiency>][compressed files][files...][-i <pattern>][-x <pattern>]
Parameters:
-A Adjusts auto-executable decompression files.
-b<working directory> Specifies a temporary directory for storing files.
-c Adds comments to each compressed file.
-d Deletes specified files from the compressed file.
-D Does not create directory names within the compressed file.
-f Updates existing files.
-F Attempts to fix corrupted compressed files.
-g Appends compressed files to an existing compressed file instead of creating a new one.
-h Online help.
-i<pattern> Compresses only files that match the condition.
-j Saves only the file names and their contents, without any directory names.
-J Removes unnecessary data from the front of the compressed file.
-k Uses MS-DOS compatible file names.
-l Replaces LF characters with LF+CR characters when compressing files.
-ll Replaces LF+CR characters with LF characters when compressing files.
-L Displays copyright information.
-m Deletes the original files after compressing and adding them to the compressed file, effectively moving the files into the compressed file.
-n<suffix string> Does not compress files with specific suffix strings.
-o Sets the modification time of the compressed file to match the most recently modified file within it.
-q Does not display the execution process.
-r Recursively processes all files and subdirectories under the specified directory.
-S Includes system and hidden files.
-t<date time> Sets the date of the compressed file to the specified date.
-T Checks whether each file in the backup file is correct.
-u Similar to the -f parameter, but also decompresses other files in the compressed file to the directory.
-v Displays the execution process or version information.
-V Preserves file attributes of the VMS operating system.
-w Adds version numbers to file names, valid only under the VMS operating system.
-x<pattern> Excludes files that match the condition during compression.
-X Does not preserve additional file attributes.
-y Directly saves symbolic links instead of the files they point to, valid only on systems like UNIX.
-z Adds comments to the compressed file.
-$ Preserves the volume name of the disk where the first compressed file is located.
-<compression efficiency> The compression efficiency is a value between 1-9.
Example
Compress all files and folders in the /home/html
directory into html.zip
in the current directory:
zip -q -r html.zip /home/html
If we are in the /home/html
directory, we can execute the following command:
zip -q -r html.zip *
Delete the file a.c
from the compressed file cp.zip
:
zip -dv cp.zip a.c