tar从压缩包里解压出指定文件

发布时间:2014-03-28 10:38:44 阅读:1249次

转: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文件,来查看有哪些更改。

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,我们需要的文件已经解压出来了。

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:tar从压缩包里解压出指定文件 出自老鄢博客 | 欢迎分享