Introduction to compression and packaging, gzip compression tools, bzip2 compression tools, xz compression tools

Why compress files

Because in a real production environment, the availability of disk space and the size of network bandwidth are both cost factors, and using compressed files can not only improve disk utilization, but also save bandwidth during transmission.

The most common file in .rar format under Windows is not recognized by Linux. The most common compressed files in Linux are usually in .tar.gz format. In addition, there are .tar, .gz, .bz2, .zip and other formats. I said before that the file suffix under the Linux system has no practical significance. , but in order to distinguish what compression tool is used, it is best to add a suffix to our compressed file.

The suffix of the compressed file is as follows:

  • .gz: Represents a file compressed by the gzip compression tool
  • .bz2: Represents a file compressed by bzip2
  • .tar: Represents a file packaged by the tar packager, (tar has no compression function, it just merges a directory into a file)
  • .tar.gz: It can be understood as being packaged by tar first and then compressed by gzip
  • .tar.bz2: It can be understood as being packaged by tar and then compressed by bzip2
  • .tar.xz: It can be understood as being packaged by tar first and then compressed by xz

gzip compression tool

The format of the gzip command is: gzip [-d#]_ filename_ , where # is the number 1~9, indicating the compression level

  • -d This parameter is used when decompressing.
  • -# indicates the compression level, the compression level is incremented from 1 to 9, and the default level is 6
  • gzip cannot compress directories
  • zcat xx.gz View compressed files
  • gzip -c_ filename_ > /xx/ filname .gz compress a file and place the compressed file in the /xx/ directory (retain the source file)
  • gunzip -c /xx/ filname .gz > /yy/_filname1 _ Extract the filname.gz compressed file in the /yy/ directory to the /yy directory and change its name to filname1 (retain the original compressed file)

bzip2 compression tool

The format of the bzip2 command is bzip2 [-d / -z]_ filename_, which only has two common options: compression -d and decompression -z. You can compress without the -z option. The compression level is also 1~9, and the default compression level is 9. The bzip2 command also cannot compress the directory, and an error will be reported when compressing the directory.

xz compression tool

The format of the xz command is xz [-d /-z], similar to bzip2, the xz -z command compresses the file, and the xz -d command decompresses. The xz command also cannot compress directories.

tar packaging tool

tar itself is a packaging tool, it can package directories into a large file, it can integrate all files into one file, which is convenient for copying or moving, tar command format: tar [- zjxcvfpP]_ filename_

  • z : Indicates that the package is compressed with gzip at the same time
  • j : Indicates compression with bzip2 at the same time
  • J : Indicates compression with xz at the same time
  • x : indicates unpacking or decompression
  • t : means to view the files in the tar package
  • c : means to create a tar package or compressed file package
  • v : indicates visualization
  • f : Indicates that it is followed by the file name (the compressed file name, or the file name of the decompressed file). When there are multiple parameters, -f should be placed at the end.
  • p : Indicates the attributes of the original file, what attributes are used before compression, and what attributes are still after compression.
  • P : Indicates that an absolute path can be used
  • -exclude filename : Indicates that the filename file should not be included when packing or compressing.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325391864&siteId=291194637