转:http://www.ttlsa.com/linux-command/only-a-single-file-tar-unzip/
http://gm100861.blog.51cto.com/1930562/899517
如果tar包很大,而只想解压出其中某个文件。方法如下:
只想解压出Redis-1.972.tar 中的Changes文件,来查看有哪些更改。
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
|
[root@nagios ~]# tar -tf Redis-1.972.tar
Redis-1.972
Redis-1.972/README
Redis-1.972/Changes
Redis-1.972/LICENSE
Redis-1.972/dist.ini
Redis-1.972/META.yml
Redis-1.972/MANIFEST
Redis-1.972/Build.PL
Redis-1.972/Makefile.PL
Redis-1.972/lib
Redis-1.972/lib/Redis.pm
Redis-1.972/t
Redis-1.972/t/01-basic.t
Redis-1.972/t/03-pubsub.t
Redis-1.972/t/11-timeout.t
Redis-1.972/t/30-scripts.t
Redis-1.972/t/00-compile.t
Redis-1.972/t/04-pipeline.t
Redis-1.972/t/05-nonblock.t
Redis-1.972/t/10-tie-list.t
Redis-1.972/t/20-tie-hash.t
Redis-1.972/t/02-responses.t
Redis-1.972/t/07-reconnect.t
Redis-1.972/t/50-fork_safe.t
Redis-1.972/lib/Redis
Redis-1.972/lib/Redis/Hash.pm
Redis-1.972/lib/Redis/List.pm
Redis-1.972/t/06-on-connect.t
Redis-1.972/scripts
Redis-1.972/scripts/publish.pl
Redis-1.972/t/08-unix-socket.t
Redis-1.972/t/42-client_cmds.t
Redis-1.972/t/release-distmeta.t
Redis-1.972/lib/Redis/Sentinel.pm
Redis-1.972/t/release-pod-coverage.t
Redis-1.972/scripts/redis-benchmark.pl
Redis-1.972/t/tlib/Test
Redis-1.972/t/tlib/Test/SpawnRedisServer.pm
Redis-1.972/tools/benchmarks
Redis-1.972/tools/benchmarks/read_vs_sysread.pl
Redis-1.972/t/tlib/Test/SpawnRedisTimeoutServer.pm
Redis-1.972/tools/benchmarks/readline_vs_sysread_vs_recv
Redis-1.972/tools/benchmarks/readline_vs_sysread_vs_recv/run.pl
Redis-1.972/tools/benchmarks/readline_vs_sysread_vs_recv/client-recv.pl
Redis-1.972/tools/benchmarks/readline_vs_sysread_vs_recv/client-sysread.pl
Redis-1.972/tools/benchmarks/readline_vs_sysread_vs_recv/client-readline.pl
Redis-1.972/tools/benchmarks/readline_vs_sysread_vs_recv/server-generator.pl
[root@nagios ~]# tar xvpf Redis-1.972.tar Redis-1.972/Changes
Redis-1.972/Changes
[root@nagios ~]# ll Redis-1.972
total 8
-rw-r--r-- 1 3957780 10902869 5894 Feb 18 07:54 Changes
|
tar命令不仅仅可以解压一个软件包,还可以解压软件包里的指定的文件。今天一朋友问我的,我才去找的资料,呵呵
查看tar包里的文件root@ubuntu:/tmp# tar -tf json-1.2.1.tgz package.xml json-1.2.1/README json-1.2.1/config.m4 json-1.2.1/config.w32 json-1.2.1/json.dsp json-1.2.1/json.c json-1.2.1/JSON_parser.c json-1.2.1/JSON_parser.h json-1.2.1/php_json.h json-1.2.1/utf8_decode.c json-1.2.1/utf8_decode.h json-1.2.1/utf8_to_utf16.c json-1.2.1/utf8_to_utf16.h json-1.2.1/tests/fail001.phpt json-1.2.1/tests/pass001.phpt json-1.2.1/tests/pass001.1.phpt json-1.2.1/tests/pass002.phpt json-1.2.1/tests/pass003.phpt
比如要解压json.c这个文件,可以使用以下
解压tar包里的指定文件
root@ubuntu:/tmp# tar xf json-1.2.1.tgz json-1.2.1/json.c tar: A lone zero block at 228 root@ubuntu:/tmp# ls json-1.2.1 json-1.2.1.tgz root@ubuntu:/tmp# ls json-1.2.1/ json.c
看到,已经被解压出来了。
我们也可以解压里面的多个文件
root@ubuntu:/tmp# tar xf json-1.2.1.tgz json-1.2.1/tests/pass003.phpt json-1.2.1/tests/pass002.phpt tar: A lone zero block at 228 root@ubuntu:/tmp# ls json-1.2.1 json-1.2.1.tgz root@ubuntu:/tmp# ls json-1.2.1/tests/ pass002.phpt pass003.phpt
OK,我们需要的文件已经解压出来了。