博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
5.4. package / compress and decompress
阅读量:7033 次
发布时间:2019-06-28

本文共 6565 字,大约阅读时间需要 21 分钟。

5.4.1. tar — The GNU version of the tar archiving utility

5.4.1.1. tar examples

tar

tar -cvf foo.tar foo/       tar contents of folder foo in foo.tartar -xvf foo.tar       extract foo.tar

5.4.1.2. gunzip

tar -zcvf foo.tar foo/       tar contents of folder foo in foo.tar.gz
tar -xvzf foo.tar.gz       extract gzipped foo.tar.gz

5.4.1.3. b2zip

b2zip
tar -jcvf foo.tar.bz2 foo/       tar contents of folder foo in foo.tar.bz2tar -jxvf foo.tar.bz2       extract b2zip foo.tar.bz2

5.4.1.4. compress

compress/uncompress
tar -Zcvf foo.tar.Z foo/       tar contents of folder foo in foo.tar.Ztar -Zxvf foo.tar.Z       extract compress foo.tar.Z

5.4.1.5. -t, --list

-t, --list list the contents of an archive

列出tar包中的文件

tar tvf neo.tar.gz
# mkdir -p /www/test.com/www.test.com/# echo helloworld > /www/test.com/www.test.com/test.txt# tar zcvf www.test.com.tar.gz /www/test.com/www.test.com/# tar ztvf www.test.com.tar.gzdrwxr-xr-x root/root         0 2013-08-08 15:24 www/test.com/www.test.com/-rw-r--r-- root/root        11 2013-08-08 15:24 www/test.com/www.test.com/test.txt# tar zxvf www.test.com.tar.gzwww/test.com/www.test.com/www/test.com/www.test.com/test.txt# find wwwwwwwww/test.comwww/test.com/www.test.comwww/test.com/www.test.com/test.txt

5.4.1.6. tar: Removing leading `/’ from member names

-P, --absolute-names don't strip leading `/'s from file names

$ tar -czvPf neo.tar.gz /home/neo/$ tar -xzvPf neo.tar.gz
tar zcvfP www.test.com.tar.gz /www/test.com/www.test.com/tar zxvfP www.test.com.tar.gz

5.4.1.7. -C, --directory=DIR

-C, --directory=DIR change to directory DIR

解压到目标目录

tar -xzvf neo.tar.gz -C /tmp
# tar zxvf www.test.com.tar.gz -C /tmpwww/test.com/www.test.com/www/test.com/www.test.com/test.txt# find /tmp/www//tmp/www//tmp/www/test.com/tmp/www/test.com/www.test.com/tmp/www/test.com/www.test.com/test.txt# rm -rf /www/test.com/*# tar zxvf www.test.com.tar.gz -C /www/test.com/www.test.com/www/test.com/www.test.com/test.txt# find /www/test.com//www/test.com//www/test.com/www.test.com/www/test.com/www.test.com/test.txt

5.4.1.8. --exclude

排除neo目录

tar --exclude /home/neo -zcvf myfile.tar.gz /home/* /etctar zcvf rpmbuild/SOURCES/netkiller-1.0.tar.gz ~/workspace/public_html/* --exclude .git --exclude .svn

5.4.1.9. -T

find . -name "*.jpg" -print >listtar -T list -czvf picture.tar.gzfind /etc/ | tar czvf xxx1.tar.gz -T -

5.4.1.10. 日期过滤

打包 2010/08/01 之后的文件和目录

tar -N '2010/08/01' -zcvf home.tar.gz /home

5.4.1.11. 保留权限

tar -zxvpf /tmp/etc.tar.gz /etc

5.4.1.12. -r, --append

追加最近7天更改过的文件

find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tar

5.4.1.13. 远程传输

tar -jcpvf - file | ssh remote "tar -jxpvf -"
tar -jcpvf - file.php | ssh root@172.16.3.1 "tar -jxpvf -"

5.4.1.14. 分卷压缩

分卷压缩一个目录:如doc在doc目录的上次目录#tar cvf doc | split -b 2m (已2M大小分卷压缩)#cat x* > doc.tar (合成分卷压缩包)

或者

#tar czvf doc.tar.gz doc/#tar czvfp - doc.tar.gz | split -b 5m#cat x* > doc.tar.gz查看压缩包里面的内容:#tar -tf doc.tar#tar -tzvf doc.tar.gz

5.4.2. cpio - copy files to and from archives

find /opt -print | cpio -o > opt.cpiofind . -type f -name '*.sh' -print | cpio -o | gzip >sh.cpio.gzcpio –i < opt.cpio

5.4.3. gzip

gzip/gunzip
# ls access.2010-{10,11}-??.logaccess.2010-10-01.log  access.2010-10-17.log  access.2010-11-02.log  access.2010-11-18.logaccess.2010-10-02.log  access.2010-10-18.log  access.2010-11-03.log  access.2010-11-19.logaccess.2010-10-03.log  access.2010-10-19.log  access.2010-11-04.log  access.2010-11-20.logaccess.2010-10-04.log  access.2010-10-20.log  access.2010-11-05.log  access.2010-11-21.logaccess.2010-10-05.log  access.2010-10-21.log  access.2010-11-06.log  access.2010-11-22.logaccess.2010-10-06.log  access.2010-10-22.log  access.2010-11-07.log  access.2010-11-23.logaccess.2010-10-07.log  access.2010-10-23.log  access.2010-11-08.log  access.2010-11-24.logaccess.2010-10-08.log  access.2010-10-24.log  access.2010-11-09.log  access.2010-11-25.logaccess.2010-10-09.log  access.2010-10-25.log  access.2010-11-10.log  access.2010-11-26.logaccess.2010-10-10.log  access.2010-10-26.log  access.2010-11-11.log  access.2010-11-27.logaccess.2010-10-11.log  access.2010-10-27.log  access.2010-11-12.log  access.2010-11-28.logaccess.2010-10-12.log  access.2010-10-28.log  access.2010-11-13.log  access.2010-11-29.logaccess.2010-10-13.log  access.2010-10-29.log  access.2010-11-14.log  access.2010-11-30.logaccess.2010-10-14.log  access.2010-10-30.log  access.2010-11-15.logaccess.2010-10-15.log  access.2010-10-31.log  access.2010-11-16.logaccess.2010-10-16.log  access.2010-11-01.log  access.2010-11-17.log# gzip access.2010-{10,11}-??.log
# ls access.2010-{0?,10,11}-??.logaccess.2010-08-28.log  access.2010-10-02.log  access.2010-10-13.log  access.2010-10-27.log  access.2010-11-06.log  access.2010-11-17.log  access.2010-11-26.logaccess.2010-08-31.log  access.2010-10-03.log  access.2010-10-14.log  access.2010-10-28.log  access.2010-11-08.log  access.2010-11-18.log  access.2010-11-27.logaccess.2010-09-24.log  access.2010-10-04.log  access.2010-10-15.log  access.2010-10-29.log  access.2010-11-09.log  access.2010-11-19.log  access.2010-11-28.logaccess.2010-09-25.log  access.2010-10-06.log  access.2010-10-17.log  access.2010-10-30.log  access.2010-11-10.log  access.2010-11-20.log  access.2010-11-29.logaccess.2010-09-26.log  access.2010-10-07.log  access.2010-10-19.log  access.2010-10-31.log  access.2010-11-11.log  access.2010-11-21.log  access.2010-11-30.logaccess.2010-09-27.log  access.2010-10-08.log  access.2010-10-20.log  access.2010-11-02.log  access.2010-11-12.log  access.2010-11-22.logaccess.2010-09-29.log  access.2010-10-09.log  access.2010-10-22.log  access.2010-11-03.log  access.2010-11-14.log  access.2010-11-23.logaccess.2010-09-30.log  access.2010-10-10.log  access.2010-10-23.log  access.2010-11-04.log  access.2010-11-15.log  access.2010-11-24.logaccess.2010-10-01.log  access.2010-10-12.log  access.2010-10-25.log  access.2010-11-05.log  access.2010-11-16.log  access.2010-11-25.log# gzip access.2010-{0?,10,11}-??.log &

5.4.4. zip, zipcloak, zipnote, zipsplit - package and compress (archive) files

*.zip

zip/unzip file[.zip]

5.4.5. RAR

sudo apt-get install rar unrar

5.4.6. 7-Zip

p7zip - 7z file archiver with high compression ratio

http://www.7-zip.org/

如果你仅仅是解压文件,只需安装下面的包即可

$ sudo apt-get install p7zip

如果你要创建7zip文件就需要安装p7zip-full

$ sudo apt-get install p7zip-full

5.4.6.1. 压缩

$ 7z a test.7z /etc/*

5.4.6.2. 浏览压缩包

$ 7z l test.7z

5.4.6.3. 解压

$ 7z e test.7z

5.4.6.4. Creates self extracting archive.

创建自解压文件

7z a -sfx a.7z *.txt

解压

./a.7z
$ unrar test.rar

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
shader 讲解的第二天 把兰伯特模型改成半兰泊特模型 函数图形绘制工具
查看>>
python3.5安装Numpy、mayploylib、opencv等额外库
查看>>
优雅绝妙的Javascript跨域问题解决方案
查看>>
Java 接口技术 Interface
查看>>
函数草稿
查看>>
织梦系统学习:文章页当前位置的写法(自认对SEO有用)
查看>>
PHP经验——PHPDoc PHP注释的标准文档(翻译自Wiki)
查看>>
vue input输入框长度限制
查看>>
深入理解Java虚拟机(类加载机制)
查看>>
在500jsp错误页面获取错误信息
查看>>
iOS-CALayer遮罩效果
查看>>
为什么需要版本管理
查看>>
五、Dart 关键字
查看>>
React Native学习笔记(一)附视频教学
查看>>
记Promise得一些API
查看>>
javascript事件之调整大小(resize)事件
查看>>
20145234黄斐《Java程序设计》第六周学习总结
查看>>
【CLRS】《算法导论》读书笔记(四):栈(Stack)、队列(Queue)和链表(Linked List)...
查看>>
hibernate 和 mybatis区别
查看>>
互联网广告综述之点击率特征工程
查看>>