For just touching Linux For people who , I'm sure it will Linux I'm confused by all kinds of file names . Don't say nothing , Just take compressed files as an example , We know that Windows It's the most common There are only two kinds of compressed files , One is ,zip, The other is .rar. But Linux Would have been different , It has .gz、.tar.gz、tgz、bz2、.Z、.tar And so on Compressed file name , Besides windows Under the .zip and .rar It can also be in Linux Next use , But in the Linux Use .zip and .rar There are too few of them . This article is about these Common compressed file for a summary , I hope you won't be confused when you come across these documents next time .

Before summarizing all kinds of compressed files , First of all, we need to understand two concepts : Pack and compress . Packaging refers to turning a large number of files or directories into a total file , Compression is to compress a large file through some compression Shrink algorithm into a small file . Why distinguish these two concepts ? In fact, it comes from Linux Many compression programs in can only compress one file , So when you want to compress a bunch of files , You just You have to use another tool to make a package of these files first , And then compress the original compression program .

ZIP

zip Probably the most widely used document compression format at present . Its biggest advantage is in different operating system platforms , such as Linux, Windows as well as Mac OS, Upper use . The disadvantage is that the compression ratio is not very high , and tar.gz and tar.gz2 Very good at compression . Gossip , Let's get to the point :

linux The following provides zip and unzip Program ,zip It's a compressor ,unzip Is the decompressor . Common command options :

-d    Delete the specified file from the compressed file , To extract to the specified directory, you need to specify -d.

-m   After compressing the file and adding the compressed file , Delete the original file , Move the file to a compressed file .

-q    Do not show instruction execution .

-r    Recursive processing , Process all files and subdirectories in the specified directory .

-S    Include system and hidden files

-v    Display instruction execution process or version information .

-i< Template Styles > Compress only eligible files .

-x< Template Styles > Exclude eligible files when compressing .

-n  < The ending string > Do not compress files with a specific suffix string .

-< Compression efficiency > The compression efficiency is between 1-9 Of The number .

give an example :

zip -r mydata.zip mydata // take mydata The directory is compressed to mydata.zip
unzip mydata.zip -d mydatabak // take mydata.zip Unzip to mydatabak Catalog , Pay attention to -d
unzip mydata.zip // take mydata.zip Unzip to the current mydata Catalog
unzip dsw\*.zip // take dsw All under directory zip Extract files to dsw Under the table of contents
unzip -v wwwroot.zip // see wwwroot.zip What's in it

RAR

To be in linux Let's deal with it .rar file , Need to install RAR for Linux, It can be downloaded from the Internet , But remember, ,RAR for Linux It's not free , Then install :

tar -xzpvf rarlinux-3.2..tar.gz
cd rar
make

So it's installed , After installation, there will be rar and unrar These two programs ,rar It's a compressor ,unrar Is the decompressor .

rar x vpsyou.rar // decompression vpsyou.rar To current directory 
rar vpsyou.rar ./vpsyou.com/ // take vpsyou.com The catalog is packaged as vpsyou.rar
rar c test.rar //
rar d test.rar file1.txt // from test.rar Delete from package file1.txt
rar e test.rar // Cannot save current directory structure , All the files are in this directory
rar x test.rar // Unzip will save the directory structure

a Add file to operation document

c Add notes to the operation document

d Delete a file from a document

e Extract the file to the current directory ( All the files are extracted to the current directory , The directory structure before compression cannot be maintained , If you want to keep the directory structure before compression , use x decompression )

x Extract the contents of the document to the current directory with the path

TAR

Tar Is in Linux Document packaging format, which is widely used in . The advantage of it is that it consumes very little CPU And time to pack the files , He's just a packaging tool , It's not about compression .

How to pack :

# tar -cvf archive_name.tar directory_to_compress

How to unpack :

# tar -xvf archive_name.tar /tmp/ // The decompression path is null when , Unzip to the current path by default

Common parameters :

-c Create a new archive
-r Appending files to the end of the archive
-x Extract files from Archives
You can remember like this , Creating a new file is c, Add to the original file with r, Extract it from the file x

-t   View content
-O Unpack files to standard output
-v Output relevant information during processing
-f Operate on normal files           // It seems to be used all the time f, otherwise , It may not show

-j   call bzip2 To compress the archive
-z call gzip To compress the archive , And -x Call gzip Complete decompression
-Z call compress To compress the archive , And -x Call compress Complete decompression

-p : Use the original properties of the original file ( Properties don't change depending on the user )
-P : You can use absolute paths to compress !
-N : Than the date that follows (yyyy/mm/dd) New ones are needed to be packaged into new files !
--exclude FILE: During compression , Don't put FILE pack !

give an example :

tar cvf dsw.tar dsw // take dsw The file is packaged as tar file 
tar czvf dsw.tar.gz dsw //z combination c when , Means to package a file as tar.gz Format
tar xzvf dsw.tar.gz //z combination x when , Means to remove a file from .tar.gz Unzip in the bag
tar zxvf dsw.tar.gz -C builds // Specify decompression dsw To builds Catalog , Pay attention to the need for -C
tar zcvfp back.tar.gz ./new // pack new All files in the directory , And keep its original properties
tar -zcvf file.tar.gz ./new/ --exclude ./new/tmp // pack new Division under directory tmp All the folders except

TAR.GZ TAR.Z TAR.BZ2

tar.gz This is the compression format I use most . It doesn't take too much to compress CPU Of , And you can get a very ideal compression ratio . And gzip The relative decompressor is gunzip

compress It's also a compression program , But it seems to use compress I'm not as good as you are gzip and bzip2 There are many people ,Z The file at the end is bzip2 Compressed results . And compress The relative decompressor is uncompress ,tar Use in -Z This parameter to call compress.

bzip2 It's a more powerful compression program ,.bz2 The file at the end is bzip2 Compressed results , This compression format has the best compression ratio of all the methods we mentioned . Of course , That means , It takes up more than the previous way CPU And time . And bzip2 The relative decompressor is bunzip2,tar Use in -j This parameter to call gzip

Be careful : Please note that z and Z And tar in c( file ),x( decompression ) In combination with

z + c = Package and use the files gzip Compress it into tar.gz

z + x = Use the compressed package gzip Unzip the package

Z + c = Package and use the files compress Compress it into tar.Z

Z + x = Use the compressed package compress decompression

j  + c = Package and use the files bzip2 Compress it into tar.bz2

j  + x =   Use the compressed package gzip Unzip the package

decompression :

tar -cZf all.tar.Z *.jpg // Will all .jpg The document is typed as tar package , And its use compress Compress 
tar -xZf all.tar.Z // Untie the bag from above
The above unpacking command will unpack the document under the current directory . Of course , You can also use this command to hold the unpacking path :
tar -zxvf archive_name.tar.gz -C /tmp/extract_here/ tar -cjf all.tar.bz2 *.jpg // Will all .jpg The files are packed into tar package , And use bzip2 Compress
tar -xjf all.tar.bz2 // Unzip the package

The above unpacking command will unpack the document under the current directory . Of course , You can also use this command to hold the unpacking path :

tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/


ubantu More articles on file decompression

  1. Free and open source .NET Multi type file decompression component SharpZipLib(.NET Component introduction 7 )

    There are six .NET Components , One of the components is the compression and decompression of writing files , Now let's talk about another kind of file decompression component SharpZipLib. In this component introduction series , Just for a brief introduction of the background and simple application of components , The reader can combine with the official when reading ...

  2. iOS Encryption method in And Extract the file

    1.Base64 encryption Base64 It's an encryption method , Reversible encryption . Base64 The printable characters in include letters A-Z.a-z. Numbers 0-9, So a total of 62 Characters ./ + fill = echo -n BC|base6 ...

  3. java Zip Extract the file

    java Zip Extract the file To decompress zip It's been two days , Looked at a lot of Google . From Baidu code, The truth is speechless , Most of them don't work . This may have something to do with my development environment . I use it Ubuntu14.04,eclips ...

  4. file &quot;c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\ttt.mdf&quot; Already compressed , But does not reside in a read-only database or filegroup . This file must be unzipped . CREATE DATABASE Failure . Some of the listed file names could not be created . Please check related errors . (.Net SqlClient Data Provider)

    problem : file "c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\ttt.mdf" Already compressed , but ...

  5. How to solve rar File decompression failed

    Attachments are often a series of compressed files , Download is the default, and the file name is a random number . As a result, there will be compressed file decompression failure after downloading. Solution : Rename to a file name with a certain order when downloading , Such as file 1, file 2, file 3 etc. How to solve the problem of single file decompression failure ? Forum ...

  6. Android Zip File decompression code

    2011-04-01 17:58:52|   classification : Android | report | Font size   subscribe   stay Android How to implement Zip Decompression of files It's a shrinking function ? because Android It has been integrated internally zlib library , Yes ...

  7. CRC File decompression problem

    CRC There are generally three possibilities for a problem 1. Your hard disk is damaged 2. Your hard drive cable is damaged 3. It could also be a problem with the motherboard and memory Hard disk bad performance hard disk used for a long time may appear all kinds of problems , And the hard disk “ Bad track ” This is one of the most common problems . Hard disk appears bad except ...

  8. python utilize unrar Realization rar Extract the file

    python Third party package unrar Can achieve rar Unzip the file , It's a dynamic library UnRAR Based on , It's packaged 1. download UnRAR Dynamic library https://pypi.python.org/pypi/unrar/0.2 ...

  9. Linux Next *.tar.gz File decompression command

    1. Compress command : Command format :tar  -zcvf   Compressed file name .tar.gz   Compressed file name You can switch to the current directory first . Both the compressed file name and the compressed file name can be added to the path . 2. Unzip command : Command format :tar  -z ...

Random recommendation

  1. C# character string string Type conversion to DateTime type perhaps string convert to DateTime?( String to nullable date type )

    stay c# in ,string Type conversion to DateTime Types are often used , As basic knowledge , Here's a summary . In general, there are many ways to transform , The most common is to use Convert.ToDateTime(string ...

  2. 【freemaker】 User defined instructions for &lt;#macro&gt;

    Test code @Test public void test07(){ try { root.put("name", " Zhang San "); freemakerUtil.fpr ...

  3. assembly debug Screenshot 2

  4. java Learning operators

    After learning variables + Constant , Now you can only simply declare variables + assignment + Print variables . But all the program has to do is process the data , The original scattered data , Processing into meaningful data , For us to use , This involves the application of operators . Common types of arithmetic operators : Add ...

  5. Vue- Custom events —— The child component modifies the value of the parent component

    How to use custom events , Modify the values inside the parent component in the child component ? Key point remember : Three event names Steps are as follows : here , Compared with this case , The parent component is defined as Second-module, The corresponding subcomponent is Three-module First step : you ...

  6. Fiddler Composer simulation post request

    In the simulation post On request , It was found that the server could not receive post Parameters Found the original request header setting problem, add the header  Content-Type: application/x-www-form-urlencoded  Post normal

  7. 【 Answer key 】Luogu P5071 [Ynoi2015] The brilliance of this moment

    as everyone knows lxl It's a cancer ,Ynoi All of them are immortal questions , The topic is well received Original title transmission gate As soon as you see that the problem has not been modified, you will know that it is a Mo team problem ( I only know Mozart ) A brief introduction to Mo team in my blog a number N Can be broken down into \(p_1^{c_1}p_2^{ ...

  8. Kubernetes – Ingress

    The user is in Kubernetes The deployed services generally run on private networks ,Pod and Service Provides hostPort,NodePort And other parameters are used to expose these service ports to K8S Node , For users to access . This method has obvious advantages ...

  9. use Filter Realize picture anti-theft chain

    First of all, inherited from FilterAttribute Class implements IActionFilter Interface , The code is as follows : //// <summary> /// Anti theft chain Filter. /// </summary& ...

  10. TCPIP Network protocol layer corresponding to RFC file

    Original address :TCPIP Network protocol layer corresponding to RFC Document author : Westwood RFC - Request For Comments  Ask for comment TCP/IP layer Network protocol RFC file Physical Layer Data ...