Linux Zip Command
Zip is a file packaging and compression utility for Unix. All the files are stored inside a single file, i.e., .zip {.zip-filename} along with the .zip extension.
- Zip is used for compressing the files to decrease the size of the file. It is used similarly as the utility .zip of file package in various operating systems such as Windows, Unix, Linux, etc.
- If we have a restricted bandwidth among two servers and wish to move the files much faster, zip can easily move the files.
- A zip program allows for multiple compressed files into an individual zip archive with details of the files including name, protection, last modification time, date, path, and check details for verifying the file integrity. The whole structure of a directory could be packed into the zip archive along with an individual command.
- The program is helpful to pack a file’s group for distribution, to save disk space, and to archive files by compressing unused directories and files temporarily.
- 3:1 and 2:1 compression ratios are normal for various text files. Zip can also store several files without any compression and it has a single compression method (deflation). Automatically, zip selects the better of the two for all the files which are to be compressed.
Syntax:
Syntax to create any zip file:
Extract files from a zip file
Unzip can extract, test, or list files from the ZIP archive which is commonly detected on Unix. The default nature is for extracting into the current directory each file through the particular ZIP archive.
Syntax:
Options in Zip Command:
1. -d Option: This option removes any file through the zip archive. We can remove any file through the archive with the help of the -d option after making a zip file.
Syntax:
2. -u Option: This option can update the file inside the zip archive. It could be used for updating the described list of files or adding new files to an existing zip file.
We can update the existing entry inside the zip archive if only it has been changed more recently as compared to the version that already existed within the zip archive.
Syntax:
3. -m Option: After zipping, this option deletes the real files. Transfer the particular files into a zip archive as it deletes the target files/directories after creating the specified zip archive.
In case, if the directory becomes unoccupied after the removal of the file, the directory is also removed. Until zip has made the archive without any error, no deletion is done.
It is useful to conserve disk space; however, it is potentially unsafe to remove every input file.
Syntax:
4. -r Option: To recursively zip a directory, use the zip command with this -r option and it will zip specified files inside the directory recursively. This option supports us to zip every file that existed inside the specified directory.
Syntax:
5. -x Option: This option can exclude the specified files in making the zip. For example, we are zipping every file in the directory and wish to exclude a few unwanted files. We can exclude the unwanted files with the help of this option.
Syntax:
6. -v Option: Print diagnostic or verbose mode version info. It enables a progress indicator display during requests verbose diagnostic and compression info about oddities of zip file structure when normally e applied to the original operations.
The diagnostic screen will be e printed if -v is the single command-line argument, and either stdout or stdin are not redirected to any file. In extension to the help screen header along with release date, version, and program name, a few pointers to the distribution sites and Info-ZIP home are given.
It then displays information about the destination environment (compiler version and type, compilation date, OS version, and the enabled options aspects used for creating a zip executable.
Syntax: