歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 使用tar命令從壓縮包裡解壓出指定文件

使用tar命令從壓縮包裡解壓出指定文件

日期:2017/3/3 15:57:15   编辑:關於Linux

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這個文件,可以使用以下

URL:http://www.bianceng.cn/OS/Linux/201410/46057.htm

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,我們需要的文件已經解壓出來了。

Copyright © Linux教程網 All Rights Reserved