《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

相关文章
|
3天前
|
Unix Shell Linux
技术笔记:linux中SIGHUP与nohup的关系
技术笔记:linux中SIGHUP与nohup的关系
|
3天前
|
Unix 关系型数据库 Linux
技术笔记:linux学习心得
技术笔记:linux学习心得
|
3天前
|
Linux
Linux每五分钟执行一次某个脚本的定时任务如何写
【6月更文挑战第28天】Linux每五分钟执行一次某个脚本的定时任务如何写
4 0
|
3天前
|
监控 Unix Shell
探秘GNU/Linux Shell:命令行的魔法世界
探秘GNU/Linux Shell:命令行的魔法世界
6 0
|
3天前
|
机器学习/深度学习 Unix Java
技术笔记:Linux之Shell脚本编程(一)
技术笔记:Linux之Shell脚本编程(一)
|
3天前
|
网络协议 算法 Linux
技术笔记:Linux学习:TCP粘包问题
技术笔记:Linux学习:TCP粘包问题
|
2月前
|
Ubuntu Linux Shell
【Linux操作系统】探秘Linux奥秘:shell 编程的解密与实战
【Linux操作系统】探秘Linux奥秘:shell 编程的解密与实战
85 0
|
2月前
|
Shell Linux C++
Linux C/C++ 开发(学习笔记二):Shell脚本编程案例
Linux C/C++ 开发(学习笔记二):Shell脚本编程案例
66 0
|
2月前
|
运维 Shell Linux
Linux 之大数据定制篇-Shell 编程
Linux 之大数据定制篇-Shell 编程
128 0
|
9月前
|
网络协议 Shell Linux
【Linux】shell编程基础(超详细,入门看这一篇就够了)(下)
【Linux】shell编程基础(超详细,入门看这一篇就够了)(下)
81 0