First I created a tar package:
[oracle@goolen test]$ ls -l
total 80084
-rw-r--r-- 1 oracle oinstall 81998360 Jul 30 09:52 test.tar.gz
us To decompress a file in a tar package, you need to first know what files are in the tar package:
[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 -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.
-t, --list list the contents of an archive
-t parameter can list all files in the tar package:
[oracle@goolen test]$ tar -tvf test.tar.gz
drwxr-xr-x oracle/oinstall 0 2014-06-24 09:48 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 15:07 home/ oracle/xiaoming/bbed/users01.dbf
-rw-r--r-- oracle/oinstall 524296192 2014-04-17 15:45 home/oracle/xiaoming/bbed/undotbs02.dbf
-rw-r--r -- oracle/oinstall 207 2014-06-24 09:48 home/oracle/xiaoming/bbed/filelist.txt
-rw-r--r-- oracle/oinstall 67246 2014-06-24 10:24 home/oracle /xiaoming/bbed/log.bbd
-rw-r--r-- oracle/oinstall 47 2013-10-17 17:52 home/oracle/xiaoming/bbed/bbed.par
[oracle@goolen test]$ 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/xiaoming/bbed/bbed .par
Check it and you will know that the above command does not actually decompress the tar package:
[oracle@goolen test]$ ls
test.tar.gz
+++ decompress the file 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.par
home/oracle/xiaoming/bbed /bbed.par
+++ Note that the tar command is followed by the file path from the -t parameter list. Do not add a "/" in front, otherwise an error will be reported. Check the decompressed file. We can see Yes, the path where the file is located is also created. Instead of decompressing the file to the current directory, creating it together with the directory should be to avoid the danger of the file with the same name being overwritten.
[oracle@goolen test]$ ls
home test.tar.gz
[oracle@goolen test]$ ls home/oracle/xiaoming/bbed/bbed.par
home/oracle/xiaoming/bbed/bbed.par
For more information on how to decompress a single file from a tarball on Linux system, please pay attention to the PHP Chinese website for related articles!