tar命令

Easter79
• 阅读 711

tar命令

 tar命令

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
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
3年前
swap空间的增减方法
(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
Java获得今日零时零分零秒的时间(Date型)
publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k