Can be used to decompress files
zip command can be used to decompress files or package files. Zip is a widely used compression program. After the file is compressed by it, a compressed file with a ".zip" extension will be generated.
zip(option)(parameter)
zip [-option] [-b path] [-t date] [-n suffix] [compressed file list] [-xi list]
-f: refresh: only changed files
-u: update: only changed or new files
-d: delete entries in zip file
-m: move to zip file (remove operating system files)
-r: Recurse into directories
-j: Junk (do not record) directory name
-0: only store
-l: Convert LF to CR LF (-ll CR LF to LF)
-1: faster compression
-9: better compression
-v: Detailed operation/print version information
-q: run quietly
-c: add a line of comments
-z: Add zip file comments
-@: Read names from standard input
-o: Make the zip file as old as the latest entry
-x: exclude the following names
-i: only include the following names
-F: Repair zip files (-FF works harder)
-D: Do not add directory entries
-A: Adjust self-extracting exe
-D: Do not add directory entries
-T: Test the integrity of the zip file
-X: exclude additional file attributes
-n: Do not compress these suffixes
-e: Encrypt
-y: Store symbolic links as links rather than referenced files
-h2: Show more help
Compress a single file, this will compress the file.txt
file into an archive named compressed.zip
zip compressed.zip file.txt
To compress multiple files, the following command will compress file1.txt
, file2.txt
, and file3.txt
into an archive file called compressed.zip
.
zip compressed.zip file1.txt file2.txt file3.txt
Compress the entire directory. The -r
parameter of the following command indicates recursive compression. This command will compress the folder
directory and all its subdirectories and files.
zip -r compressed.zip folder/
Compress files using the maximum compression ratio. The -9
parameter of the following command specifies the maximum compression ratio, although it may take longer to process.
zip -9 compressed.zip file.txt
Create a password-protected zip file. The -e
parameter of the following command will prompt the user to enter a password to create an encrypted zip file.
zip -e secure.zip file.txt
Only compress new or changed files, if compressed.zip
already exists, the -u
parameter will update file.txt
in the archive or add it to the archive if it is new
zip -u compressed.zip file.txt
Compress the file but do not preserve the directory structure. The -j
parameter will not retain the parent directory folder
of file.txt
. The location of the file in the zip will be in the root directory.
zip -j compressed.zip folder/file.txt
Pack all files and folders in the directory /home/Blinux/html/
into html.zip
in the current directory:
zip -q -r html.zip /home/Blinux/html
The above command operation is to compress files and folders with absolute addresses. The relative path directory for compression is given below. For example, in the Bliux directory, the following operations can be performed to achieve the same effect as above:
zip -q -r html.zip html
For example, in my html directory now, the zip compression command I operate is:
zip -q -r html.zip *
Compress the contents of the example/basic/
directory into the basic.zip
compressed package. -x
specifies the excluded directory. Note that it will not work without double quotes.
zip -r basic.zip example/basic/ -x "example/basic/node_modules/*" -x "example/basic/build/*" -x "example/basic/coverage/*"
The above is compressed and decompressed, and the content is stored in example/basic/
. If you want to store it in the root directory, enter the directory for compression. Currently, no suitable parameters have been found to solve this problem.
cd example/basic/ && zip -r basic.zip . -x "node_modules/*" -x "build/*" -x "coverage/*"
Compression efficiency selection:
zip -9 # 1-9 faster->better
Create a public_html
directory and ignore all files and folders, excluding any files including the text backup
.
$ zip -r public_html.zip public_html -x *backup*
The httpdocs
directory ignores .svn
files or git
files and creates an archive of all files under the directory.
$ zip -r httpdocs.zip httpdocs --exclude *.svn* --exclude *.git*
All files in the httpdocs
directory are ignored and an archive of all files in the directory ending with .log
is created.
$ zip -r httpdocs.zip httpdocs --exclude "*.log"
The command cannot be found in CentOS7
-Bash: Unzip: Command Not Found
Solution
yum install -y unzip zip