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

Linux self-study journey-basic commands (packing commands in tar format)


Preface

1. In the previous section, we described the compression and decompression commands of the compressed package in bz2 format. If you haven’t seen it, you can click the link below to enter: bzip2 command

2. In this section we describe the packaging command tar


Tip: The following is the content of this article

1. What is packing and unpacking?

Packaging can be seen as integrating multiple files into one large file. It's like many items put them in a big box and then seal them with tape. Unpacking is the other way around, tearing the tape and taking out the contents. (Packaging is not compression, that is, it will not reduce the storage size of files like compression)

2. Use of tar【packaging】

  • Command name: tar
  • The full name of the command: tar
  • Location: /usr/bin/tar
  • Execution authority: all users
  • Function description: Pack and unpack files
命令格式
tar [选项] [-f 打包后的文件名] 要打包的文件所在路径
常用选项:
-c:进行打包操作
-v:显示打包过程
-f:指定打包后的文件的文件名
(一般打包这三个选项都是一起用的)

Example:

[root@VM-0-12-centos cs]# ls
la  sk
[root@VM-0-12-centos cs]# tar -cvf ll.tar la sk
la
sk
[root@VM-0-12-centos cs]# ls
la  ll.tar  sk
[root@VM-0-12-centos cs]#

(如上,我当前目录下有两个文件,tar -cvf ll.tar la sk就是将这两个文件打包进ll.tar这个包)

tar[unpack] use

命令格式
tar [选项] 要解打包的文件
常用选项:
-x:解打包
-v:显示解打包过程
-f:指定要解打包的文件
-t:不解打包,只显示包中有哪些文件
(解打包我们一般常用选项是xvf三个,如果不需要解打包只想看里面的东西的话直接tvf就行)

Example:

[root@VM-0-12-centos cs]# ls
ll.tar
[root@VM-0-12-centos cs]# tar -xvf ll.tar
la
sk
[root@VM-0-12-centos cs]# ll
total 12
-rw-r--r-- 1 root root     0 Mar  7 15:57 la
-rw-r--r-- 1 root root 10240 Mar  7 16:40 ll.tar
-rw-r--r-- 1 root root     0 Mar  7 15:57 sk
[root@VM-0-12-centos cs]#

(tar -xvf ll.tar:解打包ll.tar这个包,将里面的文件提取到当前目录)

to sum up

In this section we learned

{ Packing and unpacking of tar= Packing: tar -cvf The file name after packing the file to be packed Unpacking: tar -xvf The file to be unpacked Only view the contents of the package: tar -tvf The tar package to be viewed }




Guess you like

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