tar命令不仅仅可以解压一个软件包,还可以解压软件包里的指定的文件。今天一朋友问我的,我才去找的资料,呵呵

 

 
  
  1. root@ubuntu:/tmp# tar -tf json-1.2.1.tgz  
  2. package.xml 
  3. json-1.2.1/README 
  4. json-1.2.1/config.m4 
  5. json-1.2.1/config.w32 
  6. json-1.2.1/json.dsp 
  7. json-1.2.1/json.c 
  8. json-1.2.1/JSON_parser.c 
  9. json-1.2.1/JSON_parser.h 
  10. json-1.2.1/php_json.h 
  11. json-1.2.1/utf8_decode.c 
  12. json-1.2.1/utf8_decode.h 
  13. json-1.2.1/utf8_to_utf16.c 
  14. json-1.2.1/utf8_to_utf16.h 
  15. json-1.2.1/tests/fail001.phpt 
  16. json-1.2.1/tests/pass001.phpt 
  17. json-1.2.1/tests/pass001.1.phpt 
  18. json-1.2.1/tests/pass002.phpt 
  19. json-1.2.1/tests/pass003.phpt 

比如要解压json.c这个文件,可以使用以下

 

 
  
  1. root@ubuntu:/tmp# tar xf json-1.2.1.tgz json-1.2.1/json.c  
  2. tar: A lone zero block at 228 
  3. root@ubuntu:/tmp# ls 
  4. json-1.2.1  json-1.2.1.tgz 
  5. root@ubuntu:/tmp# ls json-1.2.1/ 
  6. json.c 

看到,已经被解压出来了。

我们也可以解压里面的多个文件

 

 
  
  1. root@ubuntu:/tmp# tar xf json-1.2.1.tgz  json-1.2.1/tests/pass003.phpt  json-1.2.1/tests/pass002.phpt 
  2. tar: A lone zero block at 228 
  3. root@ubuntu:/tmp# ls 
  4. json-1.2.1  json-1.2.1.tgz 
  5. root@ubuntu:/tmp# ls json-1.2.1/tests/ 
  6. pass002.phpt  pass003.phpt 

OK,我们需要的文件已经解压出来了。