Linux Detailed explanation and example of compression and decompression command under


example : The contents of the current directory on the compression server are xxx.zip file


zip -r xxx.zip ./*


decompression zip File to current directory


unzip filename.zip


============================


another : Some servers are not installed zip The package cannot be executed zip command , But basically it works tar Imperative , Examples are as follows :


 


tar -zcvf /home/zdzlibs.tar.gz /home/zdz/java/zdzlibs/

============================


linux zip command


zip -r myfile.zip ./*

Compress all files and folders in the current directory into myfile.zip file ,-r Represents recursive compression of all files in the subdirectory .


2.unzip

unzip -o -d /home/sunny myfile.zip

hold myfile.zip Unzip the file to /home/sunny/

-o: Overlay file without prompting ;

-d:-d /home/sunny Indicates to extract the file to /home/sunny Under the table of contents ;


3. other

zip -d myfile.zip smart.txt

Delete from compressed file smart.txt file

zip -m myfile.zip ./rpm_info.txt

To the compressed file myfile.zip Add rpm_info.txt file

-------------------------------------------------------------------------------


To use zip To compress the file , stay shell At the prompt, type the following command :


zip -r filename.zip filesdir

 


In this case ,filename.zip On behalf of the file you created ,filesdir It means you want to place new zip Directory of files .-r Option specifies that you want to recursively (recursively) Include all included in filesdir Files in directory .


To extract zip Content of the document , Type the following command :


unzip filename.zip

 


You can use it zip The command processes multiple files and directories at the same time , The method is to list them one by one , And space them :


zip -r filename.zip file1 file2 file3 /usr/work/school 

 


The command on the top file1,file2, file3, as well as /usr/work/school Contents of contents ( Suppose this directory exists ) Compress it , Then put it in filename.zip In the file .


 


tar Command details


  -c: Set up compressed files


  -x: decompression


  -t: View content


  -r: Appends a file to the end of a compressed archive


  -u: Update the files in the original package


   These five are independent orders , Compression and decompression all need to use one of them , It can be used with other commands, but only one of them can be used . The following parameters are optional when compressing or decompressing files as required .


  -c: Set up compressed files


  -x: decompression


  -t: View content


  -r: Appends a file to the end of a compressed archive


  -u: Update the files in the original package


   The following parameters -f It's necessary


  -f: Use file name , Remember , This parameter is the last one , Only the file name can be followed .


  # tar -cf all.tar *.jpg


   This order is to put all .jpg The file is typed into a file named all.tar Bag of .-c Is to generate a new package ,-f Specifies the file name of the package .


  # tar -rf all.tar *.gif


   This order is to put all .gif Files added to all.tar In your bag .-r It means to add a document .


  # tar -uf all.tar logo.gif


   This order is to update the original tar package all.tar in logo.gif file ,-u It means to update the file .


  # tar -tf all.tar


   The order is to list all.tar All files in package ,-t List the documents


  # tar -xf all.tar


   This order is to solve the problem all.tar All files in package ,-t It means to untie


   compress


  tar –cvf jpg.tar *.jpg // Put all in the catalog jpg File package tar.jpg


  tar –czf jpg.tar.gz *.jpg // Put all in the catalog jpg File package jpg.tar after , And use it gzip compress , Generate a gzip Compressed packets , Named jpg.tar.gz


  tar –cjf jpg.tar.bz2 *.jpg // All the contents in the jpg File package jpg.tar after , And use it bzip2 compress , Generate a bzip2 Compressed packets , Named jpg.tar.bz2


  tar –cZf jpg.tar.Z *.jpg // Put all in the catalog jpg File package jpg.tar after , And use it compress compress , Generate a umcompress Compressed packets , Named jpg.tar.Z


  rar a jpg.rar *.jpg //rar Compression of formats , Need to download first rar for linux


  zip jpg.zip *.jpg //zip Compression of formats , Need to download first zip for linux


   decompression


  tar –xvf file.tar // decompression tar package


  tar -xzvf file.tar.gz // decompression tar.gz


  tar -xjvf file.tar.bz2 // decompression tar.bz2


  tar –xZvf file.tar.Z // decompression tar.Z


  unrar e file.rar // decompression rar


  unzip file.zip // decompression zip


   summary


  1,*.tar use tar –xvf decompression


  2,*.gz use gzip -d perhaps gunzip decompression


  3,*.tar.gz and *.tgz use tar –xzf decompression


  4,*.bz2 use bzip2 -d Or use bunzip2 decompression


  5,*.tar.bz2 use tar –xjf decompression


  6,*.Z use uncompress decompression


  7,*.tar.Z use tar –xZf decompression


  8,*.rar use unrar e decompression


  9,*.zip use unzip decompression


  Linux in tar Command details ( Reprinted information )


  2008 year 04 month 17 day Thursday 15:37


  tar command


  tar You can create archives for files and directories . utilize tar, Users can create archives for a specific file ( Backup files ), You can also change files in the archive , Or add a new file to the file .tar Initially by Used to create files on tape , Now? , Users can create profiles on any device , Such as floppy disk . utilize tar command , You can package a lot of files and directories into one file , This is useful for backup files It is very useful to combine several files into one file for network transmission .Linux On the tar yes GNU Version of .


   grammar :tar [ Main options + Secondary options ] File or directory


   When using this command , The main option is required , It tells tar What are you going to do , Secondary options are auxiliary , Optional .


   Main options :


  c Create a new archive . If the user wants to back up a directory or some files , Choose this option .


  r Append the file to be archived to the end of the archive file . For example, the user has made a backup file , Also found that there is a directory or some files forgotten to backup , You can use this option , Append the forgotten directory or file to the backup file .


  t List the contents of the file , See which files have been backed up .


  u Update file . That is to say , Replace the original backup file with the new file , If the file to be updated is not found in the backup file , It is appended to the end of the backup file .


  x Releasing files from archives .


   Auxiliary options :


  b This option is set for the tape drive . Followed by a number , Used to indicate the size of the block , The system default value is 20(20*512 bytes).


  f Use of archives or equipment , This option is usually required .


  k Save existing files . For example, we restore a file , In the process of restoring , Same file encountered , No coverage will be made .


  m When restoring files , Set the modification time of all files to now .


  M Creating multi volume archives , For storage on several disks .


  v Detailed report tar File information processed . If this option is not available ,tar Do not report file information .


  w Each step requires confirmation .


  z use gzip To compress / Extract the file , With this option, the archive can be compressed , But be sure to use this option to decompress when restoring .


  Linux Analysis of compressed file based on


   For the new contact Linux For those of you , Certainly Linux I'm confused by a bunch of different file names . Don't say nothing , Take compressed files as an example , We know that Windows The most common There are only two kinds of compressed files , everything ,zip, The other is .rap. however Linux It's different , It has .gz,.tar.gz,tgz,bz2,.Z,.tar And so on Compressed file name , in addition windows Under the .zip and .rar You can also Linux Under the use of , But in the Linux use .zip and .rar There are too few people . This article is about these Common compressed files are summarized , I hope you don't get dizzy the next time you come across these files .


   Before summarizing all kinds of compressed files , Two concepts must be clarified first : Packaging and compression . Packaging refers to turning a large number of files or directories into a single file , Compression is a large file through some pressure Reduce the algorithm into a small file . Why distinguish these two concepts ? In fact, it comes from Linux Many of the compressors in can only compress one file , So when you want to compress a lot of files , You just First of all, we have to use other tools to type this pile of documents into a package , And then on the original compression program for compression .


  Linux The most commonly used packing procedure is tar 了 , use tar The package generated by the program is often called tar package ,tar The command for a package file is usually .tar Ending . generate tar After package , You can use other programs to compress , So let's talk about it first tar Basic usage of commands :


  tar There are many options for the command ( use man tar You can view it ), But there are only a few commonly used options , Here's an example :


  # tar -cf all.tar *.jpg


   This order is to put all .jpg The file is typed into a file named all.tar Bag of .-c Is to generate a new package ,-f Specifies the file name of the package .


  # tar -rf all.tar *.gif


   This order is to put all .gif Files added to all.tar In your bag .-r It means to add a document .


  # tar -uf all.tar logo.gif


   This order is to update the original tar package all.tar in logo.gif file ,-u It means to update the file .


  # tar -tf all.tar


   The order is to list all.tar All files in package ,-t List the documents


  # tar -xf all.tar


   This order is to solve the problem all.tar All files in package ,-t It means to untie


   That's it tar The most basic usage of . In order to make it convenient for users to compress or decompress files while packing and unpacking ,tar Provides a special function . This is it. tar Other compressors can be called while packing or unpacking , For example, call gzip,bzip2 etc. .


  1) tar call gzip


  gzip yes GNU A compression program developed by organization ,.gz The file at the end is gzip Results of compression . And gzip The relative decompressor is gunzip.tar Use in -z This parameter is called gzip. Here's an example :


  # tar -czf all.tar.gz *.jpg


   This order is to put all .jpg Type the file into one tar package , And use it gzip compress , Generate a gzip Compressed packets , The package name is all.tar.gz


  # tar -xzf all.tar.gz


   This command is to unpack the package generated above .


  2) tar call bzip2


  bzip2 Is a compression ability stronger compression procedure ,.bz2 The file at the end is bzip2 Results of compression . And bzip2 The relative decompressor is bunzip2.tar Use in -j This parameter is called gzip. Here's an example :


  # tar -cjf all.tar.bz2 *.jpg


   This order is to put all .jpg Type the file into one tar package , And use it bzip2 compress , Generate a bzip2 Compressed packets , The package name is all.tar.bz2


  # tar -xjf all.tar.bz2


   This command is to unpack the package generated above .


  3)tar call compress


  compress Is also a compression program , But it seems to use compress People are not as good as gzip and bzip2 There are many people ..Z The file at the end is bzip2 Results of compression . And compress The relative decompressor is uncompress.tar Use in -Z This parameter is called gzip. Here's an example :


  # tar -cZf all.tar.Z *.jpg


   This order is to put all .jpg Type the file into one tar package , And use it compress compress , Generate a uncompress Compressed packets , The package name is all.tar.Z


  # tar -xZf all.tar.Z


   This command is to unpack the package generated above


   With the above knowledge , You should be able to unpack a variety of compressed files , For the following tar A summary of the series of compressed files :


  1) about .tar Ending file


  tar -xf all.tar


  2) about .gz Ending file


  gzip -d all.gz


  gunzip all.gz


  3) about .tgz or .tar.gz Ending file


  tar -xzf all.tar.gz


  tar -xzf all.tgz


  4) about .bz2 Ending file


  bzip2 -d all.bz2


  bunzip2 all.bz2


  5) about tar.bz2 Ending file


  tar -xjf all.tar.bz2


  6) about .Z Ending file


  uncompress all.Z


  7) about .tar.Z Ending file


  tar -xZf all.tar.z


   In addition, for Window Common compressed files under .zip and .rar,Linux There are also ways to decompress them :


  1) about .zip


  linux Provided by zip and unzip program ,zip It's a compression program ,unzip It's a decompressor . They have many parameter options , Here is a brief introduction , Still give an example to illustrate its usage :


  # zip all.zip *.jpg


   This order is to put all .jpg The file is compressed into a zip package


  # unzip all.zip


   The order is to all.zip Extract all the files in


  2) about .rar


   To be in linux Down processing .rar file , Installation required 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.0.tar.gz


  # cd rar


  # make


   So it's installed , After installation, there will be rar and unrar These two procedures ,rar It's a compression program ,unrar It's a decompressor . They have many parameter options , Here is a brief introduction , Still give an example to illustrate its usage :


  # rar a all *.jpg


   This order is to put all .jpg The file is compressed into a rar package , be known as all.rar, The program will .rar The extension is automatically appended to the package name .


  # unrar e all.rar


   The order is to all.rar Extract all the files in


   This is to , We've already introduced it linux Under the tar,gzip,gunzip,bzip2,bunzip2,compress,uncompress, zip,unzip,rar,unrar Etc , You should already be able to use them for .tar,.gz,.tar.gz,.tgz,.bz2,.tar.bz2,. Z,.tar.Z,.zip,.rar this 10 The compressed file is decompressed , In the future, there should be no need to download a software without knowing how to use the Linux I'm worried about it . And above Law for Unix And it's basically effective .


   This paper introduces the linux Compression program under tar,gzip,gunzip,bzip2,bunzip2, compress,uncompress,zip,unzip,rar,unrar Etc , And how to use them .tar,.gz,.tar.gz,. tgz,.bz2,.tar.bz2,.Z,.tar.Z,.zip,.rar this 10 To operate on compressed files