Linux self-study journey-basic commands (tar packaging command 2)

Linux self-study journey-basic commands (tar packaging command 2)


Preface

1. In the previous section, we talked about the basic function and use of the tar command. If you haven't read it yet, click the link below to view it: tar basic command 1

2. In this section, we continue to describe some common ways of the tar command.


Tip: The following is the content of this article

1. Review of compressed package format

We talked about the three compression formats of zip, gz, and bz2 before. Zip is commonly used in windows, so we mainly look at gz and bz2. In fact, in Linux, the two compression formats of gz and bz2 do not require separate commands to compress and decompress. , Tar command can also compress and decompress these two compression formats. In fact, there is another xz format compressed package that we did not say, that can also be compressed and decompressed with tar; so in summary, the tar command can also compress compressed packages in the three formats of gz, bz2, and xz.

Two, tar use

1. Compressed gz format

Remember the role of the three options of cvf, compress the file, display the process, and specify the compressed package name; if you want to compress the packaged file as a compressed package in gz format while packaging the file, just add the z option. (F This option must be placed after the other options, that is, at the end of the option field, otherwise an error will be reported)

[root@snljh cs]# ls
la  sk
[root@snljh cs]# tar -zcvf ll.tar.gz la sk
la
sk
[root@snljh cs]# ls
la  ll.tar.gz  sk

2. Compressed bz2 format

To compress bz2 format, just add j option.

[root@snljh cs]# ls
la  sk
[root@snljh cs]# tar -jcvf ll.tar.bz2 la sk
la
sk
[root@snljh cs]# ls
la  ll.tar.bz2  sk
[root@snljh cs]#

3. Compressed xz format

To compress the xz format, just add the J option.

[root@snljh cs]# ls
la  sk
[root@snljh cs]# tar -Jcvf ll.tar.xz la sk
la
sk
[root@snljh cs]# ls
la  ll.tar.xz  sk
[root@snljh cs]#

(Note: The xvf option is sufficient for decompression, no matter which compression format xvf can decompress)


to sum up

In this section we talked about

{ Compressed gz format: tar -zcvf xx xx compressed bz2 format: tar -jcvf xx xx compressed xz format: tar -Jcvf xx xx }



Guess you like

Origin blog.csdn.net/qq313088385/article/details/114581362