首頁  >  文章  >  php教程  >  linux系統上怎麼從tar包裡解壓縮單一文件

linux系統上怎麼從tar包裡解壓縮單一文件

高洛峰
高洛峰原創
2016-12-19 14:19:451633瀏覽

首先我創建了一個tar套件:
[oracle@goolen test]$ ls -l
total 80084
-rw-r--r-- 1 oracle oinstall 81998360 Jul 30 09:52 test.install 81998360 Jul 30 09:52 test.tar.g要解壓縮tar包中一個文件,就需要先知道這個tar包裡都有什麼些文件:
[oracle@goolen test]$ tar --help | more
Usage: tar [OPTION...] [FILE] ...
GNU `tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.

Examples:
tar tar - cf archive fate bararch. foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar      list              list the contents of an archive

-t參數可以列出tar包裡的所有文件:
[oracle@goolen test]$ tar -tvf test.tar.gz       
drwxr-xr-x oracle/oinstall   
drwxr-xr-x oracle/oinstall   06-2044-098 home/oracle/xiaoming/bbed/
-rw-r--r-- oracle/oinstall 18432 2014-04-25 09:18 home/oracle/xiaoming/bbed/bifile.bbd
-rw-r--r- - oracle/oinstall   402 2014-04-17 15:35 home/oracle/xiaoming/bbed/filelist.txt.bk
-rw-r--r-- oracle/oinstall 5251072 2014-04-14 oracle/oinstall 5251072 2014-04-14 15:074 15:071 oracle/xiaoming/bbed/users01.dbf
-rw-r--r-- oracle/oinstall 524296192 2014-04-17 15:45 home/oracle/xiaoming/bbed/undot02.dbf-rw-rw-rw-rw -- oracle/oinstall       207 2014-06-24 09:48 home/oracle/xiaoming/bbed/filelist. txt
-rw-r--r-- oracle/oinstall    txt
-rw-r--r-- oracle/oinstall     67246 2014-install. /xiaoming/bbed/log.bbd
-rw-r--r-- oracle/oinstall        47 2013-10-17 17:52 home/oracle/xiaoming/bbed/bbed.par

. tar ztf test.tar.gz 
home/oracle/xiaoming/bbed/
home/oracle/xiaoming/bbed/bifile.bbd
home/oracle/xiaoming/bbed/filelist.txt.bk
home/oracle/xiaoming/bbed /users01.dbf
home/oracle/xiaoming/bbed/undotbs02.dbf
home/oracle/xiaoming/bbed/filelist.txt
home/oracle/xiaoming/bbed/log.bbd
home/oracle/xiaohome/oracle/xiaoming/bbed/log.bbd
home/oracle/xiao .par

查看一下可以知道以上指令並沒有實際解壓縮tar套件:
[oracle@goolen test]$ ls
test.tar.gz

+++解壓bbed.par這個檔案
[oracle@goolen test] $ tar zxfv test.tar.gz /home/oracle/xiaoming/bbed/bbed.par
tar: /home/oracle/xiaoming/bbed/bbed.par: Not found in archive
tar: Exiting with failure status due to previous errors
[oracle@goolen test]$ ls
test.tar.gz
[oracle@goolen test]$ tar zxfv test.tar.gz home/oracle/xiaoming/bbed/bbed.paraobbed/oracle/ximinghome/oracle/ximingbbed /bbed.par

+++注意,tar命令後面接的是-t參數list出來的文件路徑,前面不要再加一個“/”,否則就報錯了

查看解壓出來的文件,我們可以看到,連同文件所在的路徑也一起創建了,也不是把文件解壓到當前目錄下,連同目錄一起創建應該是為了避免同名文件被覆蓋的危險吧。
[oracle@goolen test]$ ls
home  test.tar.gz
[oracle@goolen test]$ ls home/oracle/xiaoming/bbed/bbed.par 
home/oracle/xiaoming/xiaoming/bbed/bbed.par 
home/oracle/xiaoming/xiaoming/bbed/bbed.par 
home/oracle/xiaoming/bbed/bbed。

更多 linux系統上怎麼從tar包裡解壓縮單一檔案 相關文章請關注PHP中文網!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn