《Linux Shell脚本攻略》 笔记 第六章:打包压缩

《Linux Shell脚本攻略》 笔记
第六章:打包压缩
//1、打包、解包
[root@localhost program_test]# tar -cf output.tar 11.txt 22.txt 33.txt 
[root@localhost program_test]# tar -xf output.tar -C ./tar-file/  //-C指定要提取到哪个路径?
//列举出归档文件中的内容
[root@localhost program_test]# tar -tvf output2.tar 
-rw-rw-r-- yy/yy      101843 2014-12-18 07:40 33.txt
drwxrwxr-x yy/yy           0 2014-12-31 18:11 abc/
-rw-rw-r-- yy/yy           0 2014-12-31 18:11 abc/def
//
[root@localhost program_test]# tar -tf output.tar 
11.txt
22.txt
33.txt
33.txt
abc/
abc/def
//删除给定归档文件中的文件
[root@localhost program_test]# tar -f output.tar  --delete 33.txt
[root@localhost program_test]# tar -tf output.tar 
11.txt
22.txt
abc/
abc/def

2、压缩
//批量打包和压缩的实现
[root@localhost touch_more]# cat gzip_all_files.sh 
#!/bin/bash 
textfiles=`ls | grep ".txt" | xargs`

echo $textfiles
for textfile in $textfiles;
do
        tar -rvf archive.tar $textfile  //以追加的形式打包文件.
done

gzip archive.tar  //压缩归档文件


//解压缩 -x提取文件; -z采用gzip样式.
[root@localhost touch_more]# tar -zxvf archive.tar.gz -C ./test_unzip/

作者:铭毅天下

转载请标明出处,原文地址:http://blog.csdn.net/laoyang360/article/details/42364849

如果感觉本文对您有帮助,请点击支持一下,您的支持是我坚持写作最大的动力,谢谢!


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

铭毅天下

和你一起,死磕Elastic!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值