Extract tar.gz package within a file in the specified directory.

Do not want to try to extract a file from extracting tar.gz package to the specified directory, Baidu is a template to the whole, there is no example, simply baffling. It was considered to understand their own tests.
Baidu to process
tar package

TVF yourtarfile tar | fileyouwant grep,
tar xvf yourtarfile fileyouwant (full path copy above absolute path)

tar.gz 包

takes ztvf yourtargzfile | grep fileyouwant,

tar zxvf yourtarfile fileyouwant (full path copy above absolute path)

The idea is to first find the file path, and then unpack. But the above "full path to absolute path" is what the hell, after tossing considered to understand. Look at the operation.

[root@fengzw test]# pwd
/root/test
[root@fengzw test]# ls
mariadb-10.4.12.tar.gz
[root@fengzw test]# tar -tzvf mariadb-10.4.12.tar.gz | grep CMakeLists.txt
.....
-rw-rw-r-- buildbot/buildbot    17932 2020-01-27 04:43 mariadb-10.4.12/CMakeLists.txt
......
[root@fengzw test]# tar -zxvf mariadb-10.4.12.tar.gz mariadb-10.4.12/CMakeLists.txt -C ../
mariadb-10.4.12/CMakeLists.txt
[root@fengzw test]# cd ..
[root@fengzw ~]# ls
anaconda-ks.cfg  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-Vault.repo  test  tools
[root@fengzw ~]# ls test/
mariadb-10.4.12  mariadb-10.4.12.tar.gz
[root@fengzw ~]# ls test/mariadb-10.4.12
CMakeLists.txt

Switching directory to run tests:

[root@fengzw ~]# ls test/
mariadb-10.4.12.tar.gz
[root@fengzw ~]# ls tools/testtar/
[root@fengzw ~]# tar -zxvf test/mariadb-10.4.12.tar.gz mariadb-10.4.12/CMakeLists.txt -C tools/testtar/
mariadb-10.4.12/CMakeLists.txt
[root@fengzw ~]# ls tools/testtar/
[root@fengzw ~]# ls test
mariadb-10.4.12.tar.gz
[root@fengzw ~]# ls
anaconda-ks.cfg  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-Vault.repo  mariadb-10.4.12  test  tools
[root@fengzw ~]# ls mariadb-10.4.12/
CMakeLists.txt

From the above:

  1. The so-called absolute path is through tvf check out a path that began from the tar package name, rather than an absolute path system level. This is called "full path" concept.
  2. If a file is extracted, -C designated storage location does not take effect! ! !
  3. Only the default tar extract to run under the current system where the path when extracting, rather than the path of the original archive.
  4. It will generate a directory starting from the tar package name, according to the compressed package path to store extracted file.
  5. Use steps summarize: a, switching paths to the desired location to store the extracted files; b, listed in the Find path of the file to be extracted; c, extract files. (But it will generate a new directory, so switching to a path not make sense)

Guess you like

Origin blog.51cto.com/mister/2474095