51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

tar -linux tar 命令 打包压缩 —linux压缩文件为gz格式–unzip

1- 排除某个目录

https://www.baimeidashu.com/tag/tar -Pczvf /var/log/logs.tar.gz  /var/log/* --exclude=/var/log/nginx

//目录后面不要加斜杠 "/"

大家好,我是你的好朋友 白眉大叔,这篇文章主要介绍 中linux压缩文件夹命令 zip tar 上篇文章,我们讲了linux find命令这里边涉及到的知识点比较多, 也是文件4剑客 之一, 兴趣的朋友可以去看看。

linux 系统中压缩格式常见的有 tar.gz , zip ,这2种比较常见,以( tar.gz , zip)结尾的文件都是压缩文件。

跟我们windows 系统差不多,只是名字不一样 windows 常见的压缩格式有: rar, rar4, rar5, zip等。

tar 打包 压缩命令:

tar -zcvf test.tar.gz 1.txt 2.txt

语法: tar 参数 压缩包名.tar.gz 文件名称/目录

快速记忆: tar 参数选项 框子 香蕉 花瓜 茄子

参数含义:

-z: gzip 压缩

-c: 是create 创建

-v: verbos 显示过程

-f: 是file 指定文件名称

-tf: 查看压缩包里的文件名

指定压缩包 位置:

tar zcvf /home/test.tar.gz 11.txt 12txt

linux 中,我们尽量 压缩的时候使用相对路径。

查看压缩包里的文件名

tar -tf test.tar.gz

list file

排除压缩某个文件

需求: 我们压缩文件的时候,可能呢需要排除 某个文件,怎么办?

tar zcvf all.tar.gz * --exclude=1.txt

tar zxvf all.tar.gz * --exclude-from =123.txt 把排除内容放到文件中

tar 解压文件

tar xf 包名

extract file

指定解压目录 需要带大C

tar xf test.tar.gz -C /opt

zip 压缩 解压

linux zip 解压 : unzip test.zip

unzip all.zip - d /opt/

linux zip 压缩: zip test.zip 1.txt 2.txt

赞(0)
未经允许不得转载:工具盒子 » tar -linux tar 命令 打包压缩 —linux压缩文件为gz格式–unzip