ZhangZhihui's Blog  

List files in tar file:

tar -tf filename.tar.gz

tar -tvf filename.tar.gz

 

Create tar.gz file:

zzh@ZUBT:~$ tar -czvf aaa.tar.gz aaa
aaa/
aaa/a.txt

 

Extract a file called etc/default/sysstat from config.tar.gz tarball:

$ tar -ztvf config.tar.gz
$ tar -zxvf config.tar.gz etc/default/sysstat
$ tar -xvf {tarball.tar} {path/to/file}

 

Extract a tar file to a specific directory:

-C, --directory=DIR
              Change to DIR before performing any operations.  This option is order-sensitive, i.e. it affects all options that follow.

zzh@ZUBT:~$ tar -zxvf aaa.tar.gz --directory bbb (this directory must exist)
aaa/
aaa/b.txt
aaa/a.txt

zzh@ZUBT:~$ cd bbb
zzh@ZUBT:~/bbb$ ll
total 4
drwxrwxr-x 2 zzh zzh 4096 Jun 11 20:33 aaa

 

Extract a specific file to a specific directory:

-C, --directory=DIR
              Change to DIR before performing any operations.  This option is order-sensitive, i.e. it affects all options that follow.

zzh@ZUBT:~$ tar -zxvf aaa.tar.gz -C ccc aaa/a.txt

zzh@ZUBT:~$ cd ccc
zzh@ZUBT:~/ccc$ ll
drwxrwxr-x 2 zzh zzh 4096 Jun 11 20:55 aaa
zzh@ZUBT:~/ccc$ cd aaa
zzh@ZUBT:~/ccc/aaa$ ll
-rw-rw-r-- 1 zzh zzh 4 Jun 11 20:20 a.txt

 

posted on 2020-11-09 13:20  ZhangZhihuiAAA  阅读(47)  评论(0编辑  收藏  举报