Linux packaging and compression tool usage details

  • 2020-11-18 06:35:35
  • OfStack

[

Compression tools: gzip, bzip2 compression capacity gradually increased
Packaging or compression tools: tar
Package and compress tools: zip compresses better than gzip and bzip2

]

Differences between gzip and bzip2 compression tools:

gzip and bzip2 can only compress files, while zip can compress files and directories

bzip2 and gzip use the same way, and the source file disappears after compression, and the compressed file disappears after decompression. bzip2 plus 1 feature bzcat, you can view the contents of compressed files

bzip2 compresses a file
bzip2-d [zip file name] extract a compressed file
gzip [file name] compresses a file
gzip -d [zip file name] unzip a compressed file
bzcat [compressed file name] view the contents of a compressed file

bzip2 usage:

$ bzip2 file
By default, the bzip2 command attempts to compress the original file and replace it with a compressed file (the same file name plus the.bz2 extension).

Extract:

$ bunzip2 file.bz2

If file is a text file, you can view it with bzcat:

$ bzcat file.bz2

gzip is used in the same way as bzip21.

Packaging or compression tool tar:

Packaging features of the tar

tar-cvf [package to be generated] [directory name] [filename] packages directories and files
tar-xvf [package name] Unpack

Compression features of tar

tar-zcvf [compression package name to be generated. tar.gz] [file name] [directory name]
-- Package files and directories and compress them (gzip compressed)
tar-jcvf [compression package name to be generated. tar.bz2] [file name] [directory name]
-- Package files and directories and compress them (bzip2)
tar-zcvf [zip. tar.gz] --exclude [exclude packaged file or directory name] [file name] [directory name]
-- Exclude packaging a file or directory and compress it gzip
tar-tf [package name] view all the files in the package

Package and compress zip:

zip is used to package and compress files or directories
zip-r [zip package name to be generated] [file] [directory] to package and compress files and directories
unzip is used to decompress compression packs
unzip [compression package name] unzip the compression package
tar and zip: The source files are retained after compression, and the compressed files are retained after decompression.

The tar command has many options (you can see them with man tar), but there are only a few common options. Here are some examples:

# tar -cf all.tar *.jpg
This command is to type all.jpg files into one package named ES148en.tar. -ES150en is used to generate a new package. -ES151en specifies the file name of the package.

# tar -rf all.tar *.gif
This command adds all.gif files to the package of ES162en.tar. -ES164en means add file.

# tar -uf all.tar logo.gif
This command updates the logo.gif file in the original tar package ES171en.tar. -ES175en means to update the file.

# tar -tf all.tar
This command lists all files in the ES183en.tar package. -ES185en means to list files

# tar -xf all.tar
This command is to unpack all files in the all.tar package. -ES196en means unpack

These are the basic USES of tar.


Related articles: