forked from netkiller/netkiller.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.html
More file actions
339 lines (280 loc) · 17.3 KB
/
Copy pathpackage.html
File metadata and controls
339 lines (280 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>3.4. package / compress and decompress</title><link rel="stylesheet" type="text/css" href="..//docbook.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><meta name="keywords" content="shell,bash,zsh, awk,sed,curl,expect, grep,sort" /><link rel="home" href="../index.html" title="Netkiller Linux Shell 手札" /><link rel="up" href="index.html" title="第 3 章 Shell command" /><link rel="prev" href="directory.html" title="3.3. Directory and File System Related" /><link rel="next" href="datatime.html" title="3.5. date and time" /></head><body><a xmlns="" href="http://www.netkiller.cn/">Home</a> |
<a xmlns="" href="http://netkiller.github.io/">简体中文</a> |
<a xmlns="" href="http://netkiller.sourceforge.net/">繁体中文</a> |
<a xmlns="" href="/journal/index.html">杂文</a> |
<a xmlns="" href="/search.html">Search</a> |
<a xmlns="" href="http://netkiller-github-com.iteye.com/">ITEYE 博客</a> |
<a xmlns="" href="http://my.oschina.net/neochen/">OSChina 博客</a> |
<a xmlns="" href="https://www.facebook.com/bg7nyt">Facebook</a> |
<a xmlns="" href="http://cn.linkedin.com/in/netkiller/">Linkedin</a> |
<a xmlns="" href="https://zb.oschina.net/profile/725072/market">作品与服务</a> |
<a xmlns="" href="mailto:netkiller@msn.com">Email</a><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.4. package / compress and decompress</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="directory.html">上一页</a> </td><th width="60%" align="center">第 3 章 Shell command</th><td width="20%" align="right"> <a accesskey="n" href="datatime.html">下一页</a></td></tr></table><hr /></div><table xmlns=""><tr><td><iframe src="http://ghbtns.com/github-btn.html?user=netkiller&repo=netkiller.github.io&type=watch&count=true&size=large" height="30" width="170" frameborder="0" scrolling="0" style="width:170px; height: 30px;" allowTransparency="true"></iframe></td><td><iframe src="http://ghbtns.com/github-btn.html?user=netkiller&repo=netkiller.github.io&type=fork&count=true&size=large" height="30" width="170" frameborder="0" scrolling="0" style="width:170px; height: 30px;" allowTransparency="true"></iframe></td><td><iframe src="http://ghbtns.com/github-btn.html?user=netkiller&type=follow&count=true&size=large" height="30" width="240" frameborder="0" scrolling="0" style="width:240px; height: 30px;" allowTransparency="true"></iframe></td></tr></table><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="package"></a>3.4. package / compress and decompress</h2></div></div></div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="tar"></a>3.4.1. tar — The GNU version of the tar archiving utility</h3></div></div></div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931428032"></a>3.4.1.1. tar examples</h4></div></div></div>
<p>tar</p>
<pre class="screen">
tar -cvf foo.tar foo/
tar contents of folder foo in foo.tar
tar -xvf foo.tar
extract foo.tar
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931426272"></a>3.4.1.2. gunzip</h4></div></div></div>
<pre class="screen">
tar -zcvf foo.tar foo/
tar contents of folder foo in foo.tar.gz
</pre>
<pre class="screen">
tar -xvzf foo.tar.gz
extract gzipped foo.tar.gz
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931424384"></a>3.4.1.3. b2zip</h4></div></div></div>
<span class="command"><strong>b2zip</strong></span>
<pre class="screen">
tar -jcvf foo.tar.bz2 foo/
tar contents of folder foo in foo.tar.bz2
tar -jxvf foo.tar.bz2
extract b2zip foo.tar.bz2
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931422496"></a>3.4.1.4. compress</h4></div></div></div>
<span class="command"><strong>compress/uncompress</strong></span>
<pre class="screen">
tar -Zcvf foo.tar.Z foo/
tar contents of folder foo in foo.tar.Z
tar -Zxvf foo.tar.Z
extract compress foo.tar.Z
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931420576"></a>3.4.1.5. -t, --list</h4></div></div></div>
<p>-t, --list list the contents of an archive</p>
<p>列出tar包中的文件</p>
<pre class="screen">
tar tvf neo.tar.gz
</pre>
<pre class="screen">
# 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.gz
drwxr-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.gz
www/test.com/www.test.com/
www/test.com/www.test.com/test.txt
# find www
www
www/test.com
www/test.com/www.test.com
www/test.com/www.test.com/test.txt
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931417936"></a>3.4.1.6. tar: Removing leading `/’ from member names</h4></div></div></div>
<p>-P, --absolute-names don't strip leading `/'s from file names</p>
<pre class="screen">
$ tar -czvPf neo.tar.gz /home/neo/
$ tar -xzvPf neo.tar.gz
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931415456"></a>3.4.1.7. -C, --directory=DIR</h4></div></div></div>
<p>-C, --directory=DIR change to directory DIR</p>
<p>解压到目标目录</p>
<pre class="screen">
tar -xzvf neo.tar.gz -C /tmp
</pre>
<pre class="screen">
# tar zxvf www.test.com.tar.gz -C /tmp
www/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
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931412848"></a>3.4.1.8. -P, --absolute-names don't strip leading `/'s from file names</h4></div></div></div>
<pre class="screen">
tar zcvfP www.test.com.tar.gz /www/test.com/www.test.com/
tar zxvfP www.test.com.tar.gz
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931410800"></a>3.4.1.9. --exclude</h4></div></div></div>
<p>排除neo目录</p>
<pre class="screen">
tar --exclude /home/neo -zcvf myfile.tar.gz /home/* /etc
tar zcvf rpmbuild/SOURCES/netkiller-1.0.tar.gz ~/workspace/public_html/* --exclude .git --exclude .svn
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931408864"></a>3.4.1.10. -T </h4></div></div></div>
<pre class="screen">
find . -name "*.jpg" -print >list
tar -T list -czvf picture.tar.gz
find /etc/ | tar czvf xxx1.tar.gz -T -
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931407456"></a>3.4.1.11. 日期过滤</h4></div></div></div>
<p>打包 2010/08/01 之后的文件和目录</p>
<pre class="screen">
tar -N '2010/08/01' -zcvf home.tar.gz /home
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931405568"></a>3.4.1.12. 保留权限</h4></div></div></div>
<pre class="screen">
tar -zxvpf /tmp/etc.tar.gz /etc
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931404288"></a>3.4.1.13. -r, --append</h4></div></div></div>
<p>追加最近7天更改过的文件</p>
<pre class="screen">
find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tar
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931402448"></a>3.4.1.14. 远程传输</h4></div></div></div>
<span class="command"><strong>tar -jcpvf - file | ssh remote "tar -jxpvf -"</strong></span>
<pre class="screen">
tar -jcpvf - file.php | ssh root@172.16.3.1 "tar -jxpvf -"
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931400496"></a>3.4.1.15. 分卷压缩</h4></div></div></div>
<pre class="screen">
分卷压缩一个目录:如doc
在doc目录的上次目录
#tar cvf doc | split -b 2m (已2M大小分卷压缩)
#cat x* > doc.tar (合成分卷压缩包)
</pre>
<p>或者</p>
<pre class="screen">
#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
</pre>
</div>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="cpio"></a>3.4.2. cpio - copy files to and from archives</h3></div></div></div>
<p></p>
<span class="command"><strong></strong></span>
<pre class="screen">
find /opt -print | cpio -o > opt.cpio
find . -type f -name '*.sh' -print | cpio -o | gzip >sh.cpio.gz
cpio –i < opt.cpio
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="gzip"></a>3.4.3. gzip</h3></div></div></div>
<span class="command"><strong>gzip/gunzip</strong></span>
<pre class="screen">
# ls access.2010-{10,11}-??.log
access.2010-10-01.log access.2010-10-17.log access.2010-11-02.log access.2010-11-18.log
access.2010-10-02.log access.2010-10-18.log access.2010-11-03.log access.2010-11-19.log
access.2010-10-03.log access.2010-10-19.log access.2010-11-04.log access.2010-11-20.log
access.2010-10-04.log access.2010-10-20.log access.2010-11-05.log access.2010-11-21.log
access.2010-10-05.log access.2010-10-21.log access.2010-11-06.log access.2010-11-22.log
access.2010-10-06.log access.2010-10-22.log access.2010-11-07.log access.2010-11-23.log
access.2010-10-07.log access.2010-10-23.log access.2010-11-08.log access.2010-11-24.log
access.2010-10-08.log access.2010-10-24.log access.2010-11-09.log access.2010-11-25.log
access.2010-10-09.log access.2010-10-25.log access.2010-11-10.log access.2010-11-26.log
access.2010-10-10.log access.2010-10-26.log access.2010-11-11.log access.2010-11-27.log
access.2010-10-11.log access.2010-10-27.log access.2010-11-12.log access.2010-11-28.log
access.2010-10-12.log access.2010-10-28.log access.2010-11-13.log access.2010-11-29.log
access.2010-10-13.log access.2010-10-29.log access.2010-11-14.log access.2010-11-30.log
access.2010-10-14.log access.2010-10-30.log access.2010-11-15.log
access.2010-10-15.log access.2010-10-31.log access.2010-11-16.log
access.2010-10-16.log access.2010-11-01.log access.2010-11-17.log
# gzip access.2010-{10,11}-??.log
</pre>
<pre class="screen">
# ls access.2010-{0?,10,11}-??.log
access.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.log
access.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.log
access.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.log
access.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.log
access.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.log
access.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.log
access.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.log
access.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.log
access.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 &
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="zip"></a>3.4.4. zip, zipcloak, zipnote, zipsplit - package and compress (archive) files</h3></div></div></div>
<p>*.zip</p>
<span class="command"><strong>zip/unzip file[.zip]</strong></span>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="rar"></a>3.4.5. RAR</h3></div></div></div>
<pre class="screen">
sudo apt-get install rar unrar
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="7zip"></a>3.4.6. 7-Zip</h3></div><div><h4 class="subtitle">p7zip - 7z file archiver with high compression ratio</h4></div></div></div>
<p>http://www.7-zip.org/</p>
<p>如果你仅仅是解压文件,只需安装下面的包即可</p>
<pre class="screen">
$ sudo apt-get install p7zip
</pre>
<p>如果你要创建7zip文件就需要安装p7zip-full</p>
<pre class="screen">
$ sudo apt-get install p7zip-full
</pre>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931382880"></a>3.4.6.1. 压缩</h4></div></div></div>
<pre class="screen">
$ 7z a test.7z /etc/*
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931381344"></a>3.4.6.2. 浏览压缩包</h4></div></div></div>
<pre class="screen">
$ 7z l test.7z
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931380096"></a>3.4.6.3. 解压</h4></div></div></div>
<pre class="screen">
$ 7z e test.7z
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931378752"></a>3.4.6.4. Creates self extracting archive.</h4></div></div></div>
<p>创建自解压文件</p>
<pre class="screen">
7z a -sfx a.7z *.txt
</pre>
<p>解压</p>
<pre class="screen">
./a.7z
</pre>
</div>
</div>
</div><div xmlns="" id="disqus_thread"></div><script xmlns="" type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
//if(document.domain == 'netkiller.github.io'){
var disqus_shortname = 'netkiller'; // required: replace example with your forum shortname
//}else{
//var disqus_shortname = 'neochan';
//}
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script><noscript xmlns="">Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript><a xmlns="" href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a><br xmlns="" /><script xmlns="" type="text/javascript" id="clustrmaps" src="//cdn.clustrmaps.com/map_v2.js?u=r5HG&d=9mi5r_kkDC8uxG8HuY3p4-2qgeeVypAK9vMD-2P6BYM"></script><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="directory.html">上一页</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">上一级</a></td><td width="40%" align="right"> <a accesskey="n" href="datatime.html">下一页</a></td></tr><tr><td width="40%" align="left" valign="top">3.3. Directory and File System Related </td><td width="20%" align="center"><a accesskey="h" href="../index.html">起始页</a></td><td width="40%" align="right" valign="top"> 3.5. date and time</td></tr></table></div><script xmlns="">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-11694057-1', 'auto');
ga('send', 'pageview');
</script><script xmlns="" type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F997cd4a7320a82d72cb74d179118f697' type='text/javascript'%3E%3C/script%3E"));
</script><script xmlns="" type="text/javascript" src="/js/q.js"></script></body></html>