linux 打包文件

打包文件概述

  1. 多个文件或者一个目录打包成一个大文件,linux中的打包命令叫做tar
  2. tar命令就是将多个文件前后链接一起形成一个大文件
  3. tar命令并不对文件进行压缩

tar命令如下

【1】tar -cf [ 打包文件名 ][ 要打包的文件 / 列表 ]

[ylp@localhost tmp]$ tar -cf file.tar file01 file02 file03
[ylp@localhost tmp]$ tar -cf file1.tar file04

【2】tar -tf [打包文件名],查看打包文件中所有文件名

[ylp@localhost tmp]$ tar -tf file.tar 
/tmp/file01
/tmp/fiel02
/tmp/file03

【3】--delete删除打包文件中的某个特定文件

[ylp@localhost tmp]$ tar -f file.tar --delete file01
[ylp@localhost tmp]$ tar -tf file.tar 
/tmp/file03
/tmp/file02

【4】-A 选项合并两个打包文件

[ylp@localhost tmp]$ tar -f file.tar -A file01.tar
[ylp@localhost tmp]$ tar -tf file.tar
/tmp/file02
/tmp/file03
/tmp/file04

【5】-r选项 向打包文件中添加新文件

[ylp@localhost tmp]$ tar -f file.tar -r ~/fileA.txt

【6】tar -xf [ 要解包的文件名 ]

[ylp@localhost tmp]$ tar -xf file.tar -C /sampledir01

 

压缩文件

【1】压缩文件 gzip [ 要压缩的文件名 ] ,压缩后的文件自动替换源文件,自动添加.gz后缀

[ylp@localhost tmp]$ gzip file.tar

【2】解压文件 gzip -d [ 要解压的文件名 ]   解压后的文件替换了压缩文件

[ylp@localhost tmp]$ gzip -d file.tar.gz

 

gzip只能够单个的压缩文件,而不能将多个文件或者整个目录压缩到一个文件中,因此gzip往往要和tar命令一起连用,可以用tar先打包,然后用gzip压缩,反过来就要用gzip先解压,然后再用tar再解包。

tar -czf 【打包压缩生成的文件名,后缀.tar.gz】【文件列表】   将一批文件打包压缩

[ylp@localhost tmp]$ tar -czf sameple.tar.gz file01 file02 file03

tar -xzf 【要解压缩解包的文件名,后缀.tar.gz】

[ylp@localhost tmp]$ tar -xzf sameple.tar.gz 

 

 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值