Introduction to Linux compression and decompression commands

Introduction to Linux compression and decompression commands

Common compression formats: gz .bz2 .xz .zip

Command---> Suffix---> Decompression command gzip ---> .gz ---> gunzip

bzip2 ---> .bz2 ---> bunzip2

xz ---> .xz --->unxz 

zip ---> .zip --->unzip

tar ----> .tar --->tar -xvf expand archive

Commonly used archive calls for compression

tar combined archive compression and decompression gzip---> -czvf ---> -xzvf

bzip2---> -cjvf ---> -xjvf 

xz---> -cJvf ---> -xJvf

Compression ratio and compression speed:

The CPU time consumed by compression and decompression and the compression ratio vary greatly between different methods.

From the perspective of compression ratio: tar < gzip < bzip2 < xz < zip

gzip command: compression

Function: compress files Usage: gzip file (compressed file, can only compress files into *.gz files)

Note: gzip follows the file to be compressed, the original file is deleted by default -d decompression -9 sets the compression level to 6 by default

View the compressed file:

Commonly used: zcat compressed file // No need to decompress directly to view decompression: gunzip log.gz // decompression

gunzip command: decompression

Function: decompress the file Usage: gunzip file.gz (decompress file command)

bzip2: command compression

Stronger compression than gzip above. Higher compression ratio. -d decompression -9 Set the compression level to 9. The default is 6.

View compressed file

bzcat log.bz2 | more # View the contents of the compressed text file without decompression bunzip2 log.bz2 # Decompression

bunzip2 command: decompression

bunzip2 log.bz2 #decompression

xz command: compression

xz file to be compressed -d decompress -9 set compression level

View compressed file

unxz decompress xzcat view the contents of a compressed text file without decompression

unxz command: decompression

unxz decompression

Compression: zip command

Function: compress folders, files and directories Command usage: zip [option] log.zip log #log.zip compressed file name log is the file to be compressed -r: recursive compression Note:

zip The file name after the search is kept by default.

Example:

1. Compress all files under /home into myhome.zip

        zip -r myhome.zip /home/ [compress the home directory and its contained files and subfolders]

2. Unzip myhome.zip to the /opt/tmp directory unzip -d /opt/tpm myhome.zip

View compressed file

unzip log.zip #Unzip

unzip command: decompression

Function: decompress the folder Usage: unzip [option] xxx.zip

Common options -d <directory>: specify the directory where the compressed files are stored

tar command: archive/pack

Function: tar command is an archiving/packaging command, and the final packaged file is a .tar.gz file. Usage: tar [option] xxx.tar.gz packaged content (packaging directory, compressed file format .tar.gz)

-c: Generate .tar file -v: Display detailed information -f: Specify compressed file name -z: Pack and compress at the same time -x: Unpack .tar file

-x parameter: expand the archive

-x : unpack .tar file

The difference between packaging and compression:

Packaging means putting multiple files or directories together to form a total package, which is convenient for storage and transmission, but the size does not change.

Compression refers to the use of a compression algorithm to reduce the size of one or more large files or directories to achieve the purpose of compression, which can save storage space. When compressing, they are usually packaged first and then compressed.

Example:

tar -cvf benwei.tar img ---> benwei.tar (archived file)   

The file f to be archived must be in front of the archived file name. 1. Compress multiple files and compress .home/pig.txt and /home/cat.txt into pc.tar.gz

        tar -zcvf pc.tar.gz /home/pig.txt /home/cat.txt

2. Compress the /home folder into myhome.tar.gz

        tar -zcvf muhome.tar.gz /home

3. Unzip pc.tar.gz to the current directory tar -zxvf pc.tar.gz

4. Unzip myhome.tar.gz to the /opt/tmp2 directory tar -zxvf /home/myhome.tar.gz -C /opt/tmp2

View the archive:

tar -tf cc.tar # View the files in the archive without expanding it tar -xvf cc.tar # Expand the archive

Combining tar and gzip: archive ---> expand

tar -czvf myimg.tar.gz img

#Archive and call gzip compression. After completion, myimg.tar.gz contains myimg.tar, and then the original folder. Unzip: tar -xzvf myimg.tar.gz #Unzip directly to decompress the img folder

Combining tar and bzip2: archive ---> expand

tar -cjvf #Package and call bzip2 to compress tar -xjvf #Decompress

Combining tar and xz: archive ---> expand

tar -cJvf #Package and call xz to compress tar -xJvf #Decompress

In conclusion:

The Linux system is the most common operating system we use at work, and we must master its basic operating commands.

This is the end of this article about Linux compressed files and file decompression commands. For more relevant Linux compressed files and file decompression content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of Linux xz compression and decompression methods
  • Detailed explanation of Linux decompression file
  • Detailed explanation of zip compression and unzip decompression commands and their usage in Linux
  • Summary of Linux compression and decompression methods

<<:  How to add rounded borders to div elements

>>:  Login interface implemented by html+css3

Recommend

How to install Maven automatically in Linux continuous integration

Unzip the Maven package tar xf apache-maven-3.5.4...

Detailed discussion of memory and variable storage in JS

Table of contents Preface JS Magic Number Storing...

Example code showing common graphic effects in CSS styles

Let me briefly describe some common basic graphic...

Vue3 encapsulates its own paging component

This article example shares the specific code of ...

Vue+ssh framework to realize online chat

This article shares the specific code of Vue+ssh ...

The whole process record of Vue export Excel function

Table of contents 1. Front-end leading process: 2...

How to modify the time in centos virtual machine

The one above shows the system time, and the one ...

CSS to achieve the sticky effect of two balls intersecting sample code

This is an effect created purely using CSS. To pu...

Linux kernel device driver virtual file system notes

/******************** * Virtual File System VFS *...

Tutorial on installing rabbitmq using yum on centos8

Enter the /etc/yum.repos.d/ folder Create rabbitm...

Implementation of Docker to build private warehouse (registry and Harbor)

As more and more Docker images are used, there ne...

Implementation of element multiple form validation

In the project, form testing is often encountered...