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.-.el7.x86_64.rpm
/home/centos/mysql-community-release-el7-.noarch.rpm
/home/centos/cloudera-manager-centos7-cm5..0_x86_64.tar.gz
/home/centos/mysql-connector-java-5.1..jar
/home/centos/mysql/
/home/centos/mysql/mysql-community-client-5.6.-.el7.x86_64.rpm
/home/centos/mysql/mysql-community-common-5.6.-.el7.x86_64.rpm
/home/centos/mysql/mysql-community-libs-5.6.-.el7.x86_64.rpm
/home/centos/mysql/mysql-community-server-5.6.-.el7.x86_64.rpm
/home/centos/mysql/perl-5.16.-.el7.x86_64.rpm
/home/centos/mysql/perl-Carp-1.26-.el7.noarch.rpm
/home/centos/mysql/perl-Compress-Raw-Bzip2-2.061-.el7.x86_64.rpm
/home/centos/mysql/perl-Compress-Raw-Zlib-2.061-.el7.x86_64.rpm
/home/centos/mysql/perl-constant-1.27-.el7.noarch.rpm
/home/centos/mysql/perl-Data-Dumper-2.145-.el7.x86_64.rpm
/home/centos/mysql/perl-DBI-1.627-.el7.x86_64.rpm
/home/centos/mysql/perl-Encode-2.51-.el7.x86_64.rpm
/home/centos/mysql/perl-Exporter-5.68-.el7.noarch.rpm
/home/centos/mysql/perl-File-Path-2.09-.el7.noarch.rpm
/home/centos/mysql/perl-File-Temp-0.23.-.el7.noarch.rpm
/home/centos/mysql/perl-Filter-1.49-.el7.x86_64.rpm
/home/centos/mysql/perl-Getopt-Long-2.40-.el7.noarch.rpm
/home/centos/mysql/perl-HTTP-Tiny-0.033-.el7.noarch.rpm
/home/centos/mysql/perl-IO-Compress-2.061-.el7.noarch.rpm
/home/centos/mysql/perl-libs-5.16.-.el7.x86_64.rpm
/home/centos/mysql/perl-macros-5.16.-.el7.x86_64.rpm
/home/centos/mysql/perl-Net-Daemon-0.48-.el7.noarch.rpm
/home/centos/mysql/perl-parent-0.225-.el7.noarch.rpm
/home/centos/mysql/perl-PathTools-3.40-.el7.x86_64.rpm
/home/centos/mysql/perl-PlRPC-0.2020-.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Escapes-1.04-.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Perldoc-3.20-.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Simple-3.28-.el7.noarch.rpm
/home/centos/mysql/perl-Pod-Usage-1.63-.el7.noarch.rpm
/home/centos/mysql/perl-podlators-2.5.-.el7.noarch.rpm
/home/centos/mysql/perl-Scalar-List-Utils-1.27-.el7.x86_64.rpm
/home/centos/mysql/perl-Socket-2.010-.el7.x86_64.rpm
/home/centos/mysql/perl-Storable-2.45-.el7.x86_64.rpm
/home/centos/mysql/perl-Text-ParseWords-3.29-.el7.noarch.rpm
/home/centos/mysql/perl-threads-1.87-.el7.x86_64.rpm
/home/centos/mysql/perl-threads-shared-1.43-.el7.x86_64.rpm
/home/centos/mysql/perl-Time-HiRes-1.9725-.el7.x86_64.rpm
/home/centos/mysql/perl-Time-Local-1.2300-.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.-.el7.x86_64.rpm
home/centos/mysql-community-release-el7-.noarch.rpm
home/centos/cloudera-manager-centos7-cm5..0_x86_64.tar.gz
home/centos/mysql-connector-java-5.1..jar
home/centos/mysql/
home/centos/mysql/mysql-community-client-5.6.-.el7.x86_64.rpm
home/centos/mysql/mysql-community-common-5.6.-.el7.x86_64.rpm
home/centos/mysql/mysql-community-libs-5.6.-.el7.x86_64.rpm
home/centos/mysql/mysql-community-server-5.6.-.el7.x86_64.rpm
home/centos/mysql/perl-5.16.-.el7.x86_64.rpm
home/centos/mysql/perl-Carp-1.26-.el7.noarch.rpm
home/centos/mysql/perl-Compress-Raw-Bzip2-2.061-.el7.x86_64.rpm
home/centos/mysql/perl-Compress-Raw-Zlib-2.061-.el7.x86_64.rpm
home/centos/mysql/perl-constant-1.27-.el7.noarch.rpm
home/centos/mysql/perl-Data-Dumper-2.145-.el7.x86_64.rpm
home/centos/mysql/perl-DBI-1.627-.el7.x86_64.rpm
home/centos/mysql/perl-Encode-2.51-.el7.x86_64.rpm
home/centos/mysql/perl-Exporter-5.68-.el7.noarch.rpm
home/centos/mysql/perl-File-Path-2.09-.el7.noarch.rpm
home/centos/mysql/perl-File-Temp-0.23.-.el7.noarch.rpm
home/centos/mysql/perl-Filter-1.49-.el7.x86_64.rpm
home/centos/mysql/perl-Getopt-Long-2.40-.el7.noarch.rpm
home/centos/mysql/perl-HTTP-Tiny-0.033-.el7.noarch.rpm
home/centos/mysql/perl-IO-Compress-2.061-.el7.noarch.rpm
home/centos/mysql/perl-libs-5.16.-.el7.x86_64.rpm
home/centos/mysql/perl-macros-5.16.-.el7.x86_64.rpm
home/centos/mysql/perl-Net-Daemon-0.48-.el7.noarch.rpm
home/centos/mysql/perl-parent-0.225-.el7.noarch.rpm
home/centos/mysql/perl-PathTools-3.40-.el7.x86_64.rpm
home/centos/mysql/perl-PlRPC-0.2020-.el7.noarch.rpm
home/centos/mysql/perl-Pod-Escapes-1.04-.el7.noarch.rpm
home/centos/mysql/perl-Pod-Perldoc-3.20-.el7.noarch.rpm
home/centos/mysql/perl-Pod-Simple-3.28-.el7.noarch.rpm
home/centos/mysql/perl-Pod-Usage-1.63-.el7.noarch.rpm
home/centos/mysql/perl-podlators-2.5.-.el7.noarch.rpm
home/centos/mysql/perl-Scalar-List-Utils-1.27-.el7.x86_64.rpm
home/centos/mysql/perl-Socket-2.010-.el7.x86_64.rpm
home/centos/mysql/perl-Storable-2.45-.el7.x86_64.rpm
home/centos/mysql/perl-Text-ParseWords-3.29-.el7.noarch.rpm
home/centos/mysql/perl-threads-1.87-.el7.x86_64.rpm
home/centos/mysql/perl-threads-shared-1.43-.el7.x86_64.rpm
home/centos/mysql/perl-Time-HiRes-1.9725-.el7.x86_64.rpm
home/centos/mysql/perl-Time-Local-1.2300-.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  

 

最新文章

  1. 一起学微软Power BI系列-使用技巧(4)Power BI中国版企业环境搭建和帐号问题
  2. php 远程本地化无后缀图片
  3. Reactnative 随笔一
  4. 关于QCon2015感想与反思
  5. grok
  6. IDE模式下安装Windows 7强行改回ACHI后不断重启的解决方法
  7. 网页设定固定背景图片(抄袭自百度FM)
  8. 终于懂了:Delphi消息的Result域出现的原因——要代替回调函数的返回值!(MakeObjectInstance不会帮助处理(接收)消息回调函数的返回值)
  9. Python sort方法
  10. 【转载】MySQL5.7 添加用户、删除用户与授权
  11. SSMP一次请求数据处理过程分析
  12. 使用阿里云公网ip建立bind,监听客户端连接失败
  13. Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案
  14. python 递归进阶操作方法
  15. MapReduce原理1
  16. MySQL优化之——权限管理
  17. XPath Cookbook-Axes(轴)
  18. 「HEOI2014」南园满地堆轻絮
  19. 用Jmeter进行接口测试及乱码问题
  20. 【题解】洛谷P1966 [NOIP2013TG] 火柴排队(树状数组+逆序对)

热门文章

  1. 四十三:数据库之SQLAlchemy之group_by和having子句
  2. 收货确定 BAPI BAPI_GOODSMVT_CREATE
  3. Delphi DBGridEh导出Excel
  4. MySQL 常用工具sysbench/fio/tpcc等测试
  5. dapper 分页根据时间条件查询时中的一个坑
  6. java里null强转为某个类会报错吗?
  7. 跨域常见解决方案jsonp,cors示例
  8. Unity中的动画系统和Timeline(3) 混合树和动画匹配
  9. wps字体缺失,问题
  10. 对MPU6050坐标矩阵修改的学习