LinuxThe format of the two compressed package files that are common in. Tar,. GZand the. tar.gz. . Tar is simply the fileSimple topacking, the size of the file is nothave aChange, which means. Tarfile is just a package, not compressed;. tar.gzfileis ause after packinggzip CompressionGet the. file will becompressed storage, canDecreasethe size of the compressed file,easy to transmit and store;. GZa file is a file that uses thegzipCompressed files that are obtained after compression.
frequently used files for packaging and compressing commands are Tar Commands and gzip commands, respectively, are described below.
1 , gzip and gunzip
gzip the command is used to compress a single file. That is, it cannot be used to compress folders. This makes it easy to understand why There is a single tar command for packaging in Linux . So. For a folder, you can use the tar command to package it and then compress it with the gzip command.
Of course. Some of the options in tar are now available to one step, as described below.
Gunzip the command is used to gzip The resulting compressed file is decompressed. In fact. the- d option of gzip is used for decompression. So gunzip is equivalent to gzip-d.
Below are gzip a few examples of commands:
- will be a.txt compressed to the current folder under the a.txt.gz (the default name is this, after the name of the original file plus a . GZ )
- will be a.txt.gz Unzip to current folder
- Gunzip a.txt.gz
- Gzip-d a.txt.gz
It's not hard to find it here . gzip and the Gunzip when the file is compressed or uncompressed, the original file is deleted. Therefore, to preserve the source file after compression or decompression, we need to use the- C option for two commands . the- C option is to write compressed results to standard output. The Linux redirection feature is used here to write the results of compression or decompression in standard output to a file. The result of decompression or compression is obtained. Keep the original file at the same time.
- . GZ Compression
- gzip-c filename > filename.gz
- Unzip
- Gunzip-c filename.gz > FileName
- GZIP-CD filename.gz > FileName
2 , Tar
Tar commands can be used to package folders. The option to compress after packaging is also available.
Here are a few examples of how the tar command is used.
Create a compressed file . Tar
The following command will lfqy folder under the Test folder compression to Test-02-07-14.tar
TAR-CVF test-14-09-12.tar/home/lfqy/ Test
-c option represents the creation of a new tar file (i.e. compressed package); -v represents the process of display creation. -f Represents the specified newly created tar file name. -f You must follow the file name immediately after. Therefore, f Options are placed on the last side of each option.
Create a compressed file . tar.gz
in order to create a gzip compress the package, and use the Tar of the command - Z options.
The following command will lfqy folder under the Test folder compression to test-14-09-12.tar.gz .
Tar-cvzf Test-14-09-12.tar.gz/home/lfqy/test
It is important to note that, unlike the custom, when creating a compressed package. The tar command-f option is followed by the file's compressed name. The name of the compressed file is then followed.
. Tar Unzip the file
to understand the pressure . Tar file. the- C option to replace the compressed file with the - x option of the tar command . The file will be extracted to the current folder by default, assuming that you want to specify the folder to extract to, you need to use the - c option.
The following command extracts the files to the current folder
TAR-XVF Filename.tar
The following command extracts the files to the specified folder
TAR-XVF filename.tar-c/home/lfqy/file_untar/
tar.gz Unzip the file
tar.gz how files are decompressed and Tar files are also
The following command extracts the files to the current folder
TAR-XVF filename.tar.gz
The following command extracts the files to the specified folder
TAR-XVF filename.tar.gz-c/home/lfqy/file_untar/
Packaging and compression under Linux