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

Summary of 4 ways to add users to groups in Linux

Preface Linux groups are organizational units use...

21 MySQL standardization and optimization best practices!

Preface Every good habit is a treasure. This arti...

Implementation ideas for docker registry image synchronization

Intro Previously, our docker images were stored i...

How to check disk usage in Linux

1. Use the df command to view the overall disk us...

How to access MySql through IP address

1. Log in to mysql: mysql -u root -h 127.0.0.1 -p...

JavaScript basics for loop and array

Table of contents Loop - for Basic use of for loo...

How to use vue-bootstrap-datetimepicker date plugin in vue-cli 3

Demand Background Recently, I plan to use Vue and...

MySQL 5.7 installation-free configuration graphic tutorial

Mysql is a popular and easy-to-use database softw...

Detailed process of upgrading gcc (version 10.2.0) under CentOS7 environment

Table of contents Short Introduction 1. Check the...

Vue element implements table adding, deleting and modifying data

This article shares the specific code of vue elem...

Introduction to the properties of B-Tree

B-tree is a common data structure. Along with him...

Learn about JavaScript closure functions in one article

Table of contents Variable Scope The concept of c...

Docker uses dockerfile to start node.js application

Writing a Dockerfile Taking the directory automat...