Common compression formats: gz .bz2 .xz .zipCommand---> 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 compressiontar 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: compressionFunction: 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: decompressionFunction: decompress the file Usage: gunzip file.gz (decompress file command) bzip2: command compressionStronger compression than gzip above. Higher compression ratio. -d decompression -9 Set the compression level to 9. The default is 6. View compressed filebzcat log.bz2 | more # View the contents of the compressed text file without decompression bunzip2 log.bz2 # Decompression bunzip2 command: decompressionbunzip2 log.bz2 #decompression xz command: compressionxz file to be compressed -d decompress -9 set compression level View compressed fileunxz decompress xzcat view the contents of a compressed text file without decompression unxz command: decompressionunxz decompression Compression: zip commandFunction: 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 fileunzip log.zip #Unzip unzip command: decompressionFunction: decompress the folder Usage: unzip [option] xxx.zip Common options -d <directory>: specify the directory where the compressed files are stored tar command: archive/packFunction: 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 ---> expandtar -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 ---> expandtar -cjvf #Package and call bzip2 to compress tar -xjvf #Decompress Combining tar and xz: archive ---> expandtar -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:
|
<<: How to add rounded borders to div elements
>>: Login interface implemented by html+css3
Preface Linux groups are organizational units use...
There is currently a requirement that an operatio...
Preface Every good habit is a treasure. This arti...
Intro Previously, our docker images were stored i...
Software Version Windows: Windows 10 MySQL: mysql...
1. Use the df command to view the overall disk us...
1. Log in to mysql: mysql -u root -h 127.0.0.1 -p...
Table of contents Loop - for Basic use of for loo...
Demand Background Recently, I plan to use Vue and...
Mysql is a popular and easy-to-use database softw...
Table of contents Short Introduction 1. Check the...
This article shares the specific code of vue elem...
B-tree is a common data structure. Along with him...
Table of contents Variable Scope The concept of c...
Writing a Dockerfile Taking the directory automat...