"Quest for Linux" Part IV first lesson: compressing files, decompression without pressure

Source: Internet
Author: User
Tags bz2 compress archive unzip archive

650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpyowichib7qjvibxhxor1qywsiaq2jceojjrxt17i4cozxrkhuthriaeia1yic1syfm1lhdswrky6vqr2z7ew/0?wx_fmt=jpeg " alt= "0?wx_fmt=jpeg"/>

Content Introduction

1 , part fourth the first lesson: compressing files, decompression without pressure

2, The fourth part of the second lesson: SSH connection, safe and fast


compress files, decompress without pressure


Recently, I moved from South France to Paris because I changed my job. Toss it for a long time.


The network has been using the public wireless network, the signal is not. Wireless Internet box box has been said to network, but I think the line on the wall is a problem. Anyway, you can't use your own to tell the WiFi box.


But also to continue to find a house, just work the first week, a lot of things, so recently stopped a long time. Excuse me.


But now it's a start again. Wood, hahaha, haha ~


Shimo, The ...


Part IV We will talk about some of the Linux network knowledge points. Since we are talking about networking, we can first describe how to compress and decompress files, because when we transfer files over the network, we usually compress them first.


When it comes to compressing files, if you are a Windows user, that should be no stranger to RAR and zip two formats. Generally under windows, we will use compression decompression software such as Winrar,7zip. Some of the software is charged, such as WinRAR.


Under Linux, we have a lot of free compression decompression software to choose from, such as Gzip and bzip2. However, Gzip and bzip2 cannot compress multiple files at the same time, only one file at a time.


However, the open source community such as Linux is awesome, and they have a software tar, which is a lot of Linux under the program. Tar can compress multiple files at the same time.


Of course, Linux also has the decompression zip and rar format software.


There are no technical difficulties in this lesson, but some of the concepts are more important.


As a gossip, leisure bubble foot bar ... Of course, do not use the water to wash your feet after the tea ...


Tar command: Archive multiple files


First, we need to figure out two concepts: packaging and compression.


    1. Packaging, is to convert multiple files into a total file, this total file we commonly called Archive, English is "archive, archive" meaning.

    2. Compression is a large file that is converted to a small file by some compression algorithm.


So, in fact, the tar commands mentioned in the introduction, the gzip and BZIP2 commands are used in this way:


    1. Use tar to archive multiple files as a total file, called archive.

    2. Compress the archive into smaller files with the gzip or BZIP2 command.


Can be used to describe this process:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpyowichib7qjvibxhxor1qywsiaq7cicyy7ti1ldbpbrwfn46wfm78fermicc9pcd0oynhuh5ejukp7iacbba/0?wx_fmt=jpeg " alt= "0?wx_fmt=jpeg"/>


Therefore, we will first introduce the TAR command, and then learn the gzip and BZIP2 commands. Of course, we will also learn how to unzip files in zip and rar format under Linux.


The zip and RAR formats can be archived and compressed at the same time.


Merging multiple files into one file


Let's do the actual operation.


Suppose I now create a directory, called compression, is the meaning of English "compression", and then create a directory in this folder, called Tutorial, is the meaning of English "tutorial". In the Tutorial directory, I put three C language source files. As shown in the following:


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymj2wm96miiaianoqxrgb0wq1ksrwiciahwrpfhschpp0u1g15aewdhkywsvwedubx0w7sakibhis6j6qg/0?wx_fmt=jpeg " alt= "0?wx_fmt=jpeg"/>


We can archive these three files with the tar command.


-CVF: Creating a tar Archive


We can do this to create a tar archive:


TAR-CVF Tutorial.tar tutorial/


The three option parameters for the TAR command are indicated separately:


    1. C:C is the abbreviation for Create, which means "created".

    2. V:V is the abbreviation for verbose, which means "redundancy". The details of the operation are displayed.

    3. F:F is the abbreviation for file, which represents "files". Specifies the archive file.


After executing the above command, you can create Tutorial.tar this archive from the Tutorial folder (which contains ws.c,test.c,hanio.c three files).


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymj2wm96miiaianoqxrgb0wq1ofukg5icysg2un1bcibopbfcdice70paujewxnfdpwmvrmyfdzvyv5wca/0?wx_fmt=jpeg " alt= "0?wx_fmt=jpeg"/>


Because the V option is added, three files are listed for archiving.


Do we have to put three files in a directory such as tutorial before we can use tar to archive them?


No, we can also directly archive files, do not need to put all the files in a directory, as follows:


TAR-CVF Archive.tar file1.txt file2.txt file3.txt


The file.txt,file2.txt,file3.txt will be archived as Archive.tar.


-TF: Displays the contents of the archive without unlocking the archive


We can look at the contents of the archive Tutorial.tar we just generated using the TF option parameter.


TAR-TF Tutorial.tar


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymj2wm96miiaianoqxrgb0wq1j1htgri4nrva3wcjrboetiqzerqmf2icmorrzkexpiaz26h9ld9aoxrq/0?wx_fmt=jpeg "alt = "0?wx_fmt=jpeg"/>


As you can see, Tutorial.tar this file, the first contains the directory of tutorial, there are three files in the directory: WS.C,TEST.C,HANIO.C


Generally, it's a good idea to put all your files in one directory before you can create an archive. Because if you get the archive file is not included in the directory (as above TAR-CVF Archive.tar file1.txt file2.txt file3.txt so), and there are hundreds of files in it, you will be unpacked to your home directory, it will mess.


-RVF: Append file to archive


For example:


TAR-RVF Archive.tar File_extra.txt


Indicates that the File_extra.txt file is added to the Archive.tar archive.


-XVF: Unlocking the Archive


It is the opposite of the-CVF operation. Unpack the generated archive. X is the abbreviation for extract, which means "extract, take Out".


TAR-XVF Tutorial.tar


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymj2wm96miiaianoqxrgb0wq1fc0zrdrj9j5x1klfz81icjvkmrjzoqlrrgd8zd4vn8is3jvddw8bglg/0?wx_fmt=jpeg "alt= "0?wx_fmt=jpeg"/>


Gzip and bzip2 command: Compress archive


Now that we've learned to use the TAR command to create an archive, let's learn how to compress the archive.


The compression commands commonly used in Linux are gzip and bzip2. function is similar.


    1. Gzip: more often.

    2. BZIP2: Not so often. BZIP2 has a greater compression rate than gzip, but it is more time-consuming.


The use of these two commands is also simple, simply passing in the archive to be compressed as a parameter. After compression, the name of the archived suffix will also change.


    1. . tar.gz: This is the file suffix name that is compressed with the gzip command.

    2. . tar.bz2: This is the file suffix name that was compressed with the BZIP2 command.


The usage of the two compression commands is as follows:


Gzip Tutorial.tar
Bzip2 Tutorial.tar


The tutorial.tar.gz and tutorial.tar.bz2 two compressed files are generated separately.


If you want to extract the compressed files generated by these two commands separately, you can use the Gunzip and bunzip2 two commands:


Gunzip tutorial.tar.gz
BUNZIP2 tutorial.tar.bz2


Archive and compress at the same time with the tar command


Previously we only introduced the tar command of the archive function, in fact, we can use the TAR command to complete the archive and compression operation, one go.


Of course, adding an option parameter to the TAR command to complete the archive operation, or to call the gzip or BZIP2 command to complete the compression operation.


-ZCVF: Archive, then use gzip to compress the archive


TAR-ZCVF tutorial.tar.gz tutorial/


One step, archive, compress, generate tutorial.tar.gz files from the Tutorial directory.


To decompress, you can also one step:


TAR-ZXVF tutorial.tar.gz


Believe that users of common Linux systems should be familiar with this command.


-JCVF: Archive, then use bzip2 to compress the archive


TAR-JCVF tutorial.tar.bz2 tutorial/


One step, archive, compress, generate tutorial.tar.bz2 files from the Tutorial directory.


To decompress, you can also one step:


TAR-JXVF tutorial.tar.bz2


Zcat,zmore,zless: Directly displays the contents of a file compressed with gzip


Cat,more and less three commands we are already familiar with, and are used to display the contents of a file.


If it is compressed files, such as the tutorial.tar.gz we generated above, if directly with the Cat,more or less command to display, it will be garbled.


Cat tutorial.tar.gz


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymj2wm96miiaianoqxrgb0wq1fsuj1fecgq3ibmliaua1ucsgr2n39jl5jyohppxsyciadqiceydiah5coww/0?wx_fmt=jpeg " alt= "0?wx_fmt=jpeg"/>


However, the contents of a file compressed with the gzip command can be displayed with the zcat,zmore,zless command:


Zcat tutorial.tar.gz


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpymj2wm96miiaianoqxrgb0wq1ibk2sa8drv3v8hjrd6pgwccxv00m17fmpaxjiaogxkluliw8dotk1luw/0?wx_fmt=jpeg "alt = "0?wx_fmt=jpeg"/>


Unzip and Unrar commands: Extracting zip and rar files


Although it is common in the Linux world to have a compressed file ending with. tar.gz and. tar.bz2, if a Windows user sends you a compressed file, most likely a compressed file that ends in. zip or. rar, then how do you decompress such foreign objects from the Windows World under Linux?


Don't worry, we can use the unzip and Unrar commands to extract the compressed files separately from the. zip and. rar formats.


Unzip: Unzip compressed files in. zip format


This program is not installed by default in the general Linux distribution, and we can install it using the following command:


sudo apt-get install unzip


After installation, to unzip the. zip file, you can:


Unzip Archive.zip


It's simple.


If you do not want to unlock the. zip file, you can add the-l parameter only if you want to see the contents of it:


Unzip-l Archive.zip


In Linux, although not common, but sometimes we also need to create a. zip format file, we can install the zip this program:


sudo apt-get install zip


To generate a compressed file in. zip format, you can:


Zip-r Archive.zip archive/


Note that there is an-r parameter, which needs to be added, and if not added, only the empty folder will be compressed. With the-r parameter, all files in the directory and subdirectories are compressed recursively.


Unrar: Extracting compressed files in. rar format


Similar to unzip, the command to install Unrar is as follows:


sudo apt-get install Unrar


After installation, to unzip the. rar format of the compressed file, you can:


Unrar e Archive.rar


As you can see, some surprises, because E is not in front of this option parameter--life is always unexpected, isn't it? Unrar the author of this command is obviously not taking the usual road.


If you do not want to untie the. rar file, just want to see the contents of the words, you can add the L parameter (yes, not add-):


Unrar L Archive.rar


What if I want to create a compressed file in. rar format in Linux?


Sorry, the. rar format compression software is not publicly available, and the extracted software is free of charge. If you want to compress the RAR file, you can only buy the fee software.


Linux also has RAR this software, you can also download the installation, but this is a trial software, to a certain number of days, will be charged. However, the zip software is free of charge.


The fourth part of the second lesson notice


Today's class will come here, together refueling it!

Next lesson we learn:SSH connection, safe and fast

This article is from the "Programmer Alliance Frogoscar" blog, so be sure to keep this source http://4526621.blog.51cto.com/4516621/1704893

"Quest for Linux" Part IV first lesson: compressing files, decompression without pressure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.