tar归档
创建归档文件:
命令格式:tar 选项 打包后的文件名 要打包的文件
-c 创建
-v 详细信息
-f 文件
制作压缩文件 [root@localhost ~]# dd if=/dev/zero of=2M bs=2M count=1 [root@localhost ~]# dd if=/dev/zero of=4M bs=4M count=1 [root@localhost ~]# dd if=/dev/zero of=6M bs=6M count=1 [root@localhost ~]# tar -cvf a.tar 2M 4M 6M 2M 4M 6M [root@localhost ~]# ls 1.txt 2M 4M 6M anaconda-ks.cfg a.tar initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面 打包和压缩 -z gzip [root@localhost ~]# ls 1.txt 2M 4M 6M anaconda-ks.cfg a.tar b.tar.gz initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面 [root@localhost ~]# file b.tar.gz b.tar.gz: gzip compressed data, from Unix, last modified: Thu Dec 7 11:13:10 2023 bzip2 [root@localhost ~]# tar -cjvf c.tar.bz2 2M 4M 6M 2M 4M 6M [root@localhost ~]# file c.tar.bz2 c.tar.bz2: bzip2 compressed data, block size = 900k xz文件 [root@localhost ~]# tar -cJvf c.tar.xz 2M 4M 6M 2M 4M 6M [root@localhost ~]# file c.tar.xz c.tar.xz: XZ compressed data 查看压缩包中的文件 [root@localhost ~]# tar -tvf a.tar -rw-r--r-- root/root 2097152 2023-12-07 11:08 2M -rw-r--r-- root/root 4194304 2023-12-07 11:10 4M -rw-r--r-- root/root 6291456 2023-12-07 11:10 6M 解压缩包 [root@localhost ~]# ls anaconda-ks.cfg backup.tar.gz initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面 创建文件1-4.txt [root@localhost ~]# touch {1,2,3,4}.txt 压缩 [root@localhost ~]# tar -czvf 123.tar.gz {1,2,3,4}.txt 1.txt 2.txt 3.txt 4.txt [root@localhost ~]# ls 123.tar.gz 2.txt 4.txt backup.tar.gz 公共 视频 文档 音乐 1.txt 3.txt anaconda-ks.cfg initial-setup-ks.cfg 模板 图片 下载 桌面 此时删除文件 [root@localhost ~]# rm -rf {1,2,3,4}.txt [root@localhost ~]# ls 123.tar.gz anaconda-ks.cfg backup.tar.gz initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面 可以看见txt文件没有了 使用tar -xvf进行解压可以看见文件被解压出来了 [root@localhost ~]# tar -xvf 123.tar.gz 1.txt 2.txt 3.txt 4.txt [root@localhost ~]# ls 123.tar.gz 2.txt 4.txt backup.tar.gz 公共 视频 文档 音乐 1.txt 3.txt anaconda-ks.cfg initial-setup-ks.cfg 模板 图片 下载 桌面