tar -cf all.tar *.jpg
这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。
tar -rf all.tar *.gif
这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。
tar -uf all.tar logo.gif
这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。
tar -tf all.tar
这条命令是列出all.tar包中所有文件,-t是列出文件的意思
tar -xf all.tar
这条命令是解出all.tar包中所有文件,-x是解开的意思
如:
root@d001:~# tar -cvf centos.tar /home/centos
tar: 从成员名中删除开头的“/”
/home/centos/
/home/centos/.bash_logout
/home/centos/.bash_profile
/home/centos/.bashrc
/home/centos/.bash_history
/home/centos/jdk-8u144-linux-x64.tar.gz
/home/centos/.oracle_jre_usage/
/home/centos/.oracle_jre_usage/7e61647adaca41a2.timestamp
/home/centos/.ssh/
/home/centos/.ssh/known_hosts
/home/centos/.ssh/id_rsa
/home/centos/.ssh/id_rsa.pub
/home/centos/.ssh/authorized_keys
/home/centos/mysql-community-libs-5.6.38-2.el7.x86_64.rpm
/home/centos/mysql-community-release-el7-5.noarch.rpm
/home/centos/cloudera-manager-centos7-cm5.13.0_x86_64.tar.gz
/home/centos/mysql-connector-java-5.1.44.jar
/home/centos/mysql/
/home/centos/mysql/mysql-community-client-5.6.38-2.el7.x86_64.rpm
/home/centos/mysql/mysql-community-common-5.6.38-2.el7.x86_64.rpm
/home/centos/mysql/mysql-community-libs-5.6.38-2.el7.x86_64.rpm
/home/centos/mysql/mysql-community-server-5.6.38-2.el7.x86_64.rpm
/home/centos/mysql/perl-5.16.3-292.el7.x86_64.rpm
/home/centos/mysql/perl-Carp-1.26-244.el7.noarch.rpm
/home/centos/mysql/perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm
/home/centos/mysql/perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm
/home/centos/mysql/perl-constant-1.27-2.el7.noarch.rpm
/home/centos/mysql/perl-Data-Dumper-2.145-3.el7.x86_64.rpm
/home/centos/mysql/perl-DBI-1.627-4.el7.x86_64.rpm
/home/centos/mysql/perl-Encode-2.51-7.el7.x86_64.rpm
/home/centos/mysql/perl-Exporter-5.68-3.el7.noarch.rpm
/home/centos/mysql/perl-File-Path-2.09-2.el7.noarch.rpm
/home/centos/mysql/perl-File-Temp-0.23.01-3.el7.noarch.rpm
/home/centos/mysql/perl-Filter-1.49-3.el7.x86_64.rpm
/home/centos/mysql/perl-Getopt-Long-2.40-2.el7.noarch.rpm
/home/centos/mysql/perl-HTTP-Tiny-0.033-3.el7.noarch.rpm
/home/centos/mysql/perl-IO-Compress-2.061-2.el7.noarch.rpm
/home/centos/mysql/perl-libs-5.16.3-292.el7.x86_64.rpm
/home/centos/mysql/perl-macros-5.16.3-292.el7.x86_64.rpm
/home/centos/mysql/perl-Net-Daemon-0.48-5.el7.noarch.rpm
/home/centos/mysql/perl-parent-0.225-244.el7.noarch.rpm
/home/centos/mysql/perl-PathTools-3.40-5.el7.x86_64.rpm
/home/centos/mysql/perl-PlRPC-0.2020-14.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Escapes-1.04-292.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Perldoc-3.20-4.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Simple-3.28-4.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Usage-1.63-3.el7.noarch.rpm
/home/centos/mysql/perl-podlators-2.5.1-3.el7.noarch.rpm
/home/centos/mysql/perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm
/home/centos/mysql/perl-Socket-2.010-4.el7.x86_64.rpm
/home/centos/mysql/perl-Storable-2.45-3.el7.x86_64.rpm
/home/centos/mysql/perl-Text-ParseWords-3.29-4.el7.noarch.rpm
/home/centos/mysql/perl-threads-1.87-4.el7.x86_64.rpm
/home/centos/mysql/perl-threads-shared-1.43-6.el7.x86_64.rpm
/home/centos/mysql/perl-Time-HiRes-1.9725-3.el7.x86_64.rpm
/home/centos/mysql/perl-Time-Local-1.2300-2.el7.noarch.rpm
root@d001:~# cd /home/centos/
root@d001:~# tar -tf centos.tar
home/centos/
home/centos/.bash_logout
home/centos/.bash_profile
home/centos/.bashrc
home/centos/.bash_history
home/centos/jdk-8u144-linux-x64.tar.gz
home/centos/.oracle_jre_usage/
home/centos/.oracle_jre_usage/7e61647adaca41a2.timestamp
home/centos/.ssh/
home/centos/.ssh/known_hosts
home/centos/.ssh/id_rsa
home/centos/.ssh/id_rsa.pub
home/centos/.ssh/authorized_keys
home/centos/mysql-community-libs-5.6.38-2.el7.x86_64.rpm
home/centos/mysql-community-release-el7-5.noarch.rpm
home/centos/cloudera-manager-centos7-cm5.13.0_x86_64.tar.gz
home/centos/mysql-connector-java-5.1.44.jar
home/centos/mysql/
home/centos/mysql/mysql-community-client-5.6.38-2.el7.x86_64.rpm
home/centos/mysql/mysql-community-common-5.6.38-2.el7.x86_64.rpm
home/centos/mysql/mysql-community-libs-5.6.38-2.el7.x86_64.rpm
home/centos/mysql/mysql-community-server-5.6.38-2.el7.x86_64.rpm
home/centos/mysql/perl-5.16.3-292.el7.x86_64.rpm
home/centos/mysql/perl-Carp-1.26-244.el7.noarch.rpm
home/centos/mysql/perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm
home/centos/mysql/perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm
home/centos/mysql/perl-constant-1.27-2.el7.noarch.rpm
home/centos/mysql/perl-Data-Dumper-2.145-3.el7.x86_64.rpm
home/centos/mysql/perl-DBI-1.627-4.el7.x86_64.rpm
home/centos/mysql/perl-Encode-2.51-7.el7.x86_64.rpm
home/centos/mysql/perl-Exporter-5.68-3.el7.noarch.rpm
home/centos/mysql/perl-File-Path-2.09-2.el7.noarch.rpm
home/centos/mysql/perl-File-Temp-0.23.01-3.el7.noarch.rpm
home/centos/mysql/perl-Filter-1.49-3.el7.x86_64.rpm
home/centos/mysql/perl-Getopt-Long-2.40-2.el7.noarch.rpm
home/centos/mysql/perl-HTTP-Tiny-0.033-3.el7.noarch.rpm
home/centos/mysql/perl-IO-Compress-2.061-2.el7.noarch.rpm
home/centos/mysql/perl-libs-5.16.3-292.el7.x86_64.rpm
home/centos/mysql/perl-macros-5.16.3-292.el7.x86_64.rpm
home/centos/mysql/perl-Net-Daemon-0.48-5.el7.noarch.rpm
home/centos/mysql/perl-parent-0.225-244.el7.noarch.rpm
home/centos/mysql/perl-PathTools-3.40-5.el7.x86_64.rpm
home/centos/mysql/perl-PlRPC-0.2020-14.el7.noarch.rpm
home/centos/mysql/perl-Pod-Escapes-1.04-292.el7.noarch.rpm
home/centos/mysql/perl-Pod-Perldoc-3.20-4.el7.noarch.rpm
home/centos/mysql/perl-Pod-Simple-3.28-4.el7.noarch.rpm
home/centos/mysql/perl-Pod-Usage-1.63-3.el7.noarch.rpm
home/centos/mysql/perl-podlators-2.5.1-3.el7.noarch.rpm
home/centos/mysql/perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm
home/centos/mysql/perl-Socket-2.010-4.el7.x86_64.rpm
home/centos/mysql/perl-Storable-2.45-3.el7.x86_64.rpm
home/centos/mysql/perl-Text-ParseWords-3.29-4.el7.noarch.rpm
home/centos/mysql/perl-threads-1.87-4.el7.x86_64.rpm
home/centos/mysql/perl-threads-shared-1.43-6.el7.x86_64.rpm
home/centos/mysql/perl-Time-HiRes-1.9725-3.el7.x86_64.rpm
home/centos/mysql/perl-Time-Local-1.2300-2.el7.noarch.rpm
tar提供了一种特殊的功能。这就是tar可以在打包或解包的同时调用其它的压缩程序,比如调用gzip、bzip2等。
1) tar调用gzip
gzip是GNU组织开发的一个压缩程序,.gz结尾的文件就是gzip压缩的结果。与gzip相对的解压程序是gunzip。tar中使用-z这个参数来调用gzip。
下面来举例说明一下:
将所有.jpg的文件打成一个tar包,并且将其用gzip压缩,生成一个gzip压缩过的包,包名为all.tar.gz
tar -czf all.tar.gz *.jpg
将上面产生的包解开。
tar -xzf all.tar.gz
2) tar调用bzip2
bzip2是一个压缩能力更强的压缩程序,.bz2结尾的文件就是bzip2压缩的结果。与bzip2相对的解压程序是bunzip2。tar中使用-j这个参数来调用gzip。
下面来举例说明一下:
将所有.jpg的文件打成一个tar包,并且将其用bzip2压缩,生成一个bzip2压缩过的包,包名为all.tar.bz2
tar -cjf all.tar.bz2 *.jpg
将上面产生的包解开
tar -xjf all.tar.bz2
3)tar调用compress
compress也是一个压缩程序,但是好象使用compress的人不如gzip和bzip2的人多。.Z结尾的文件就是bzip2压缩的结果。与 compress相对的解压程序是uncompress。tar中使用-Z这个参数来调用gzip。
下面来举例说明一下:
将所有.jpg的文件打成一个tar包,并且将其用compress压缩,生成一个uncompress压缩过的包,包名为all.tar.Z
tar -cZf all.tar.Z *.jpg
将上面产生的包解开
tar -xZf all.tar.Z