How many compressed file formats are there in linux? And how to operate compressed files?

Introduction: Review of the last issue

    Last time we learned how to add a linux user and set a password, and view a status of the currently logged-in user in linux. In this chapter we talk about a file format that we are very familiar with. Compressed files , compressed files must be familiar to everyone, don't tell me that you have never seen compressed files. In our windows, compressed files can be said to be a very common file format. We download software, data, and installation packages generally in the format of compressed files. What are the compressed file formats in our linux system? And how to compress and decompress a file? In this chapter, we will learn, all the commands that must be mastered.

1. Compression format of .gz in linux

   Compression command: gzip filename

     Unzip command: gunzip filename

    Gzip is a commonly used compression command in linux.  Next, we will demonstrate how to compress a file (Figure 1). The suffix of the file format compressed using gzip is .gz , and (Figure 2) is decompressed by gunzip.

      Note: 1. Compressed folders are not supported. In the compressed folder, it will prompt "This is a directory". In Windows, you can compress whatever you want. (image 3)

               2. The compressed file system will only save the compressed .gz file, and the source file will not be saved.

        


Second, use tar to pack and unpack

   Packaging command: tar -cvfz packaged file name source file name

     Unpacking command: tar -xzfv specifies the unpacked file

    We are using gzip compression. Since the folder cannot be compressed, we first package the folder with tar, and then compress it .

    As shown in Figure 1, we first use tar to package, and display the detailed directory of the package, which is the effect of the "-v" option . Then use gzip to compress, and finally generate a .tar.gz file . We usually download the source code in linux in this format. Some students may think that there will be two-step operations in this way. Can it be simplified into one-step operation? Of course, it is also possible. When we pack a directory, add the "-z" option to compress at the same time (Figure 1).

     We also use tar to unpack (Figure 2).   

     


    Let's take a look at the options of tar when packing and unpacking

Options for tar packaging
1 -c Pack
2-v Show details when packing (optional)
3 -f specify filename
4 -z Compress while packing

options when unpacking tar
1 -x unpack
2-v Show details when unpacking (optional)
3 -f Specifies the unpacked filename
4 -z Unpack while unpacking

3 Unzip and compress files using zip

    Compression command: zip compressed file name needs to be compressed file name

    Unzip command: unzip filename

   Note: 1 zip compression will save the source file

             2 Use the -r option to compress directories

             3 Because zip is an old format, it supports the zip format on windows, linux, and mac

            

4 Decompress and compress files using bzip2

    Compression command: bzip2 -k filename

     Unzip command: bunzip2 -k filename

    The function of the "-k" option is to keep the source file. If it is added, it means to keep it, and if it is not added, it means not to keep it.

     在我们需要压缩很大的文件的时候,推荐使用bzip2,但是也有个缺点不能对目录进行压缩。(图1)我们演示了如何使用bzip2来压缩和解压文件,既然我们这个bzip2不支持压缩目录,当然我们也可以结合tar打包来使用,先打包,在使用bzip2来压缩只需要我们把tar打包中的选项"-z"换成" -j" ,就可以打包压缩成.tar.bzip2格式的压缩文件了,解压也是同样的道理(图2)。

      

    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325534535&siteId=291194637