There are many types of compressed file formats. Here are only a few common compression formats, such as zip, tar, tar.gz, and rar.
ZIP
The ZIP file format is a file format for data compression and document storage, formerly known as Deflate, and its inventor was Phil Katz, who announced the format in January 1989. ZIP usually uses the suffix ".zip" and its MIME format is application/zip. Currently, the ZIP format is one of several mainstream compression formats, with competitors including the RAR format and the open source 7z format. In terms of performance, RAR and 7z formats have higher compression rates than ZIP formats, and 7-Zip has gradually been applied in more fields because of the free compression tools provided. Microsoft has built-in support for the zip format since the Windows ME operating system. Even if the decompression software is not installed on the user's computer, the compressed file in the zip format can be opened and made. OS X and the popular Linux operating system also provide the zip format. similar support. Therefore, when disseminating and distributing files on the Internet, the zip format is often the most commonly used choice.
--Baidu Encyclopedia
From the above introduction, we can know that the compression rate of zip format is not high, but mainstream operating systems have built-in support for zip format, and zip files can be decompressed without installing external software.
zip
The zip command is relatively simple to use. The common format is zip -rv foo.zip foo
(foo can be a directory, and files can be added after foo, which will be compressed into foo.zip together when compressing)
Below I've -q
used silent compression at 64.7%.
unzip
It can be used directly during decompression, and can unzip foo.zip
also be added -d
to specify the decompression path (or a folder that does not exist), which -q
is silent decompression.
RAR
RAR is a proprietary file format used for compression, archiving and packaging of files. RAR's full name is: Roshal Archive (meaning "Rochelle's Archive"), and its developer is Eugene Roshal. The first public version, RAR 1.3, was released in 1993. Roshal originally wrote the Dos version of the RAR program to encode and decode files, and later the program was ported to other platforms, most notably the ported version of Win RAR on the Windows platform. Eugene Roshal later made the source code of the decoding program public, but the encoding program remained private. Because of its unique compression algorithm, RAR can basically achieve lossless compression, and can also meet a higher compression ratio while ensuring a certain compression speed. However, the RAR compression algorithm also has certain defects. Since the RAR file header needs to occupy a part of the space, the amount of original data compressed in the second file is small, and when the compressed space is small, the compressed file may be larger than the original one. The file is larger. RAR files have many redundant records, mainly because the compressed data is damaged during the compression process. In order to ensure lossless compression, there will be more recovery records, and these recovery records also take up a certain amount of space. However, volume compression is a very prominent advantage of RAR, dividing the source file into multiple small files, which is beneficial to decompress the source file. If all data is compressed into the same data area, the compression ratio can be greatly increased, but this compression method must decompress all the files located before it in the same data area when decompressing one of the individual files, which is not conducive to Individual decompression of files. RAR has a mature encryption algorithm. After version 2.0, the AES algorithm is used for encryption. The AES algorithm is more difficult to crack. In the absence of a password, only brute force cracking can be used, which has a certain guarantee for the security of data.
--Baidu Encyclopedia
There is no pre-installed rar command in Ubuntu, you need to use sudo apt-get install rar
to install it.
rar uses the a
option to compress and the x
option to decompress. The following is just a list of commands, there are many switch
options (such as -r and -inul to be used later).
weird
When using rar a foo.rar
to compress, if no list of compressed files is added, the current path will be compressed by default.
-r
is a switch option for recursive compression, which can test_file/*
also to achieve the same effect.
-inul
It is also a switch option that does not print any compressed information.
This time the compression rate is 61.8% (better than zip's 64.7%).
rar x
When rar x foo.rar
decompressing with , if no target directory is added, it will be decompressed to the current directory by default.
GZIP
GZIP was originally created by Jean-loup Gailly and Mark Adler for file compression on UNIX systems. We often use files with the suffix .gz in Linux, and they are in GZIP format. It has become a very common data compression format, or a file format, used on the Internet today.
When no parameter option is added to the gzip command, the default is the compression function, and decompression can be realized when the -d
option .
gzip -r
It seems that gzip can only compress and decompress a single file, but cannot archive it. I feel that this command has little effect.
First look at the directory structure of the files to be compressed:
gzip -r
After compressing with , it was found that all subfiles were compressed separately.
gzip -dr
After the above compression, the test file size becomes 25M, use gzip -dr
to decompress the target folder, and the file size returns to 34M. The compression rate of this .gz is 73.5%.
TAR
A compression and packaging tool on Unix and Unix-like systems, which can combine multiple files into one file, and the suffix of the packaged file is also "tar". The tar file format has become a POSIX standard, originally POSIX.1-1988 and currently POSIX.1-2001. This program was originally designed to back up files to tape (tape archive), hence the name tar.
--Baidu Encyclopedia
As mentioned earlier, gzip can only compress but not package. Using tar can perfectly solve this problem. Its job is to package, and it can also decompress in multiple formats.
tar packaging
The main operation of tar is packing (archiving) and unpacking, which does not compress files.
Use tar -cvf foo.tar foo1 foo2 ...
to archive,
-c
create a new archive
-v
Show detailed archive process Work
-f
with archive files
The unpacking command is to extract the file tar -xvf foo.tar
-x
from the archive.
-C
Specify the unpacking path, the default is the current path
-
It is also fine not to add before the parameter options of tar , this is a bit special.
The main function of tar is archiving. Comparing the size of the files before and after archiving, we find that tar archiving still has a little compression effect, but the effect is small.
Tip: The -c
and -f
options will throw an error when used alone.
tar.gz
A file suffixed with tar.gz is a compressed file that is common under Linux and macOS. Both Linux and macOS can directly decompress and use this compressed file.
This is the most commonly used compression format in Linux. The method of use is similar to that of tar, except that the compression function is added on the basis of tar packaging and unpacking.
The function of the -z
parameter is to use gzip to compress or decompress the tar package when unpacking.
compression
When compressing, use decompress tar -zcvf foo.tar.gz foo...
-z
via gzip
-c
Create a new archive
-v
Show detailed archiving process Work
-f
with archived files
Judging from the compressed size, the compression rate is 61.8%, which is comparable to rar compression (there is only one test sample, and only approximate conclusions can be drawn).
unzip
Use tar -zxvf foo.tar.gz
to decompress,
-x
Extract the file from the archive
-C
Specify the path to unpack, the default file current path