首页 > 编程知识 正文

怎么打包tar,tar打包指定文件

时间:2023-05-05 11:45:00 阅读:279245 作者:4282

linux系统中常见的压缩包格式有:.tar.gz 、.tar、 .gz、 .tgz、 .zip …

tar命令

tar命令表示:
1.在linux系统中可以将多个文件打包在一起,表示压缩
2.在linux系统中可以将打包文件解压成普通文件,表示解压
命令用法:tar 可选项参数 压缩文件名称 需要打包文件
通常对图片类的文件进行压缩、源文件/源代码*.h,.c,.cpp,*.php等、通常不对MP3,MP4等音频视频文件进行解压
可选项参数

-z 通过gzip压缩或解压-c 创建新的tar包-v 显示详细的tar命令的执行过程-f 指定压缩文件的名称-x 解开tar包-C 解压的目录路径-p 保持文件的原有属性-h 打包软链接文件指向真实的源文件

企业真实生产案例

yun install -y httpd 在线安装systemctl reatart httpd 开启服务[root@xxx /2020]# :lltotal 0drwxr----x. 2 xxzh xxzh 6 Mar 28 05:04 033[root@xxx /2020]# :tar -zcvf 033.tar.gz ./033./033/[root@xxx /2020]# :lltotal 4drwxr----x. 2 xxzh xxzh 6 Mar 28 05:04 033-rw-r--r--. 1 root root 111 Mar 29 22:10 033.tar.gz 压缩[root@xxx /2020]# :tar ztvf 033.tar.gz drwxr----x xxzh/xxzh 0 2020-03-28 05:04 ./033/ 查看压缩包内容[root@xxx /2020]# :tar -zxvf 033.tar.gz ./033/ 解压 企业级真实生产案例

1.排除打包的目录

用法:--exclude=PATH[root@xxx /2020/033]# :lltotal 0-rw-r--r--. 1 root root 0 Mar 29 22:19 a.txt-rw-r--r--. 1 root root 0 Mar 29 22:19 b.txt-rw-r--r--. 1 root root 0 Mar 29 22:19 c.mp3[root@xxx /2020/033]# :cd ../[root@xxx /2020]# :tar zcvf 011.tar.gz ./033 --exclude=033/*.mp3 ./033/./033/a.txt./033/b.txt 排除了*.mp3的文件[root@xxx /2020]# :tar ztvf 011.tar.gz drwxr----x xxzh/xxzh 0 2020-03-29 22:19 ./033/-rw-r--r-- root/root 0 2020-03-29 22:19 ./033/a.txt-rw-r--r-- root/root 0 2020-03-29 22:19 ./033/b.txt

1.打包软链接文件
可选项加上h
tar ztvfh 压缩包名字 需要打包文件
2.扩展打包/etc目录里的所有普通文件
find命令可以查找/etc下的所有普通文件

find /etc -type f实现:tar zcvf 压缩包名称 `find /etc -type f```反引号 表示优先执行

在使用拷贝时,文件过大无法拷贝
tar带gzip属性的分割参数 split命令

yum install -y lrzszsplit命令参数-b 表示设置每一个分割单元的大小,比如200M-d 指定分割压缩包后缀为数字的形式,默认为字母,变成数字-a 设定分割序列的长度,默认是2,表示2位数命令实现:[root@xxx /2020/033]# :lltotal 4268-rw-r--r--. 1 root root 4366570 Mar 8 23:58 1.png-rw-r--r--. 1 root root 0 Mar 29 22:19 a.txt-rw-r--r--. 1 root root 0 Mar 29 22:19 b.txt-rw-r--r--. 1 root root 0 Mar 29 22:19 c.mp3[root@xxx /2020/033]# :tar zcvf - 1.png|split -b 1M -d -a 2 - 1.tar.gz.1.png[root@xxx /2020/033]# :lltotal 7448-rw-r--r--. 1 root root 4366570 Mar 8 23:58 1.png-rw-r--r--. 1 root root 1048576 Mar 29 22:55 1.tar.gz.00-rw-r--r--. 1 root root 1048576 Mar 29 22:55 1.tar.gz.01-rw-r--r--. 1 root root 1048576 Mar 29 22:55 1.tar.gz.02-rw-r--r--. 1 root root 110094 Mar 29 22:55 1.tar.gz.03-rw-r--r--. 1 root root 0 Mar 29 22:19 a.txt-rw-r--r--. 1 root root 0 Mar 29 22:19 b.txt-rw-r--r--. 1 root root 0 Mar 29 22:19 c.mp3

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。