tar——压缩数据/解压数据内容

命令语法: tar zcvf  生成压缩包路径/压缩包.tar.gz    压缩数据01,02,03....

巧记:

压缩名称为tar.gz,可以理解为tar命令,gz取压缩类型gizp的前2个辅音字母

参数说明:
       z --- 数据压缩方式 gzip (--gzip, --gunzip, --ungzip   filter the archive through gzip)
       c --- 创建一个压缩文件(create               create a new archive)
       v --- 显示压缩过程(verbose              verbosely list files processed)
       f --- 指定压缩包路径信息
       将链接文件进行压缩处理时:
       tar zcvhf  生成压缩包路径/压缩包.tar.gz  需要进行压缩链接文件
       h --- 指定压缩链接文件所指定源文件

注意压缩的参数建议加上-,因为很多命令的参数都加-

先创建压缩包,再把文件放到里面,解压缩时磁盘和CPU都会比较卡

注意不要压缩软链接,但是不知道文件是否为软链接,那么就可以加上参数h

[root@centos71 ~]# tar  --help | grep   "\-h"
-h, --dereference follow symlinks; archive and dump the files they
--hard-dereference follow hard links; archive and dump the files they
-?, --help give this help list

因为/只有一个,所以要去掉/

[root@centos71 ~]# tar   -zcvf   /tmp/etc.tar.gz  /etc
[root@centos71 ~]# ll -h /tmp/etc.tar.gz
-rw-r--r-- 1 root root 9.8M Dec 13 21:19 /tmp/etc.tar.gz
[root@centos71 ~]# du -s /etc/
32096 /etc/
[root@centos71 ~]# du -sh /etc/
32M /etc/
[root@centos71 ~]# tar  -xvf  /tmp/etc.tar.gz
[root@centos71 ~]# du -sh etc/
32M etc/

进行批量压缩数据

[root@centos71 ~]# find  -type f  -name   "m*.conf"    |  xargs   tar zcvf  /test/m.tar.gz
./etc/libreport/events.d/mailx_event.conf
./etc/libreport/plugins/mantisbt.conf
./etc/libreport/plugins/mantisbt_format.conf
./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
./etc/libreport/plugins/mantisbt_formatdup.conf
./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
./etc/libreport/plugins/mailx.conf
./etc/ld.so.conf.d/mariadb-x86_64.conf
./etc/man_db.conf
./etc/mke2fs.conf
[root@centos71 ~]# ls /test
m.tar.gz
[root@centos71 ~]# tar  -tf  /test/m.tar.gz
./etc/libreport/events.d/mailx_event.conf
./etc/libreport/plugins/mantisbt.conf
./etc/libreport/plugins/mantisbt_format.conf
./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
./etc/libreport/plugins/mantisbt_formatdup.conf
./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
./etc/libreport/plugins/mailx.conf
./etc/ld.so.conf.d/mariadb-x86_64.conf
./etc/man_db.conf
./etc/mke2fs.conf
[root@centos71 ~]# ls  /test
m.tar.gz
[root@centos71 ~]# find -type f -name "m*.conf" -exec tar zcvf /test/m.conf.tar.gz {} \;
./etc/libreport/events.d/mailx_event.conf
./etc/libreport/plugins/mantisbt.conf
./etc/libreport/plugins/mantisbt_format.conf
./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
./etc/libreport/plugins/mantisbt_formatdup.conf
./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
./etc/libreport/plugins/mailx.conf
./etc/ld.so.conf.d/mariadb-x86_64.conf
./etc/man_db.conf
./etc/mke2fs.conf
[root@centos71 ~]# ls /test
m.conf.tar.gz m.tar.gz
[root@centos71 ~]# tar  -tf  /test/m.conf.tar.gz
./etc/mke2fs.conf
[root@centos71 ~]# find  -type f  -name   "m*.conf"     -exec tar zcvf /test/m.conf.tar.gz {} +;
./etc/libreport/events.d/mailx_event.conf
./etc/libreport/plugins/mantisbt.conf
./etc/libreport/plugins/mantisbt_format.conf
./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
./etc/libreport/plugins/mantisbt_formatdup.conf
./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
./etc/libreport/plugins/mailx.conf
./etc/ld.so.conf.d/mariadb-x86_64.conf
./etc/man_db.conf
./etc/mke2fs.conf
[root@centos71 ~]# tar -tf /test/m.conf.tar.gz
./etc/libreport/events.d/mailx_event.conf
./etc/libreport/plugins/mantisbt.conf
./etc/libreport/plugins/mantisbt_format.conf
./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
./etc/libreport/plugins/mantisbt_formatdup.conf
./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
./etc/libreport/plugins/mailx.conf
./etc/ld.so.conf.d/mariadb-x86_64.conf
./etc/man_db.conf
./etc/mke2fs.conf
[root@centos71 ~]# ls /test
m.conf.tar.gz m.tar.gz
[root@centos71 ~]#

文件打包压缩——tar的更多相关文章

  1. .Net Core 文件打包压缩

    最近项目需要实现多文件打包的功能,尝试了一些方法,最后发现使用  ICSharpCode.SharpZipLib 最符合项目的要求. 具体实现如下: 1.在 Nuget 中安装  ICSharpCod ...

  2. Linux_文件打包,压缩,解压

    一.压缩命令 文件格式:*.gz 命令:gzip 文件名 (ps:不能压缩目录,切压缩后不保留原文件) 压缩前 -rw-r--r--. 1 root root 315 Sep 6 21:03 df.t ...

  3. Linux文件打包压缩、解压缩、备份命令使用方法(转载)

    对于刚刚接触Linux的人来说,一定会给Linux下一大堆各式各样的文件名给搞晕.别个不说,单单就压缩文件为例,我们知道在Windows下最常见的压缩文件就只有两种,一是,zip,另一个是.rar.可 ...

  4. Linux 常见文件打包压缩命令

    .tar 解包: tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!)       参数说明:         - ...

  5. Linux-文件查找-打包压缩-tar

    1.文件查找工具locate,find 1.1  locate locate 查询系统上预建的文件索引数据库 /var/lib/mlocate/mlocate.db 索引的构建是在系统较为空闲时自动进 ...

  6. webpack提取图片文件打包压缩

    抽离图片文件打包到指定路径下 压缩抽离的图片资源 配置生成html中的图片路径 一.准备测试环境 //工作区间 src//文件夹 index.js//入口文件 index.css//样式文件 inde ...

  7. shell 命令 文件(解)压缩 tar,zip, gzip,bzip2

    1.gzip / gunzip [ gzip data.c]  对文件进行压缩,生成 data.c.gz    同时删除了原文件    同时压缩两个文件     [gunzip  data.c.gz  ...

  8. Windows下将文件打包压缩成 .tar.gz格式

    1.下载 “7-ZIP”,安装完成后进入需要打包的文件夹 2. 右击选择“添加到压缩包” 3.压缩格式:tar 4. 得到.tar文件,将其打包 5. 压缩格式为:gzip 6. 得到tar.gz格式 ...

  9. linux 文件打包压缩成.tar.gz

    tar czvf beian.drcluod.cn.20180509.tar.gz ./beian.drcloud.cn/*

随机推荐

  1. Linux监控命令之==>top

    一.命令说明 top 命令能够实时监控系统的运行状态,并且可以按照CPU.内存和执行时间进行排序,同时top 命令还可以通过交互式命令进行设定显示,通过top 命令可以查看即时活跃的进行. 二.参数说 ...

  2. 超详细 SpringMVC @RequestMapping 注解使用技巧

    @RequestMapping 是 Spring Web 应用程序中最常被用到的注解之一.这个注解会将 HTTP 请求映射到 MVC 和 REST 控制器的处理方法上. 在这篇文章中,你将会看到 @R ...

  3. is_selected()检查是否选中该元素

    is_selected()检查是否选中该元素,一般针对单选框,复选框,返回的结果是bool 值, 以百度登录页面为案例,来验证"下次自动登录"是否勾选,默认是勾选的,返回的结 果应 ...

  4. 【ABAP系列】SAP S/4 HANA的SMARTFORMS如何切换到非word编辑器

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP S/4 HANA的SMA ...

  5. 【MM系列】SAP MB5B中FI凭证摘要是激活的/结果可能不正确 的错误

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MB5B中FI凭证摘要是激活 ...

  6. mysql5.6修改密码并授权所有远程用户可登陆

    1.my.ini文件,删除最后一行的"skip-grant-tables 2.执行"use mysql;",使用mysql数据库; 3.执行:update mysql.u ...

  7. 虚拟机三种网络模式及Xshell与Centos7虚拟机连接

    一.虚拟机的三种网络模式 1.桥接模式 a.该模式下的虚拟机可以上外网 b. 局域网之内的主机可以访问该虚拟机(做共享服务器使用) c. 该虚拟机可以和宿主机进行通信 d. 同一台主机相同模式下的虚拟 ...

  8. 【读书笔记】Git使用

    初始设置本地Git 首先来设置使用 Git 时的姓名和邮箱地址.名字请用英文输入. $ git config --global user.name "Firstname Lastname&q ...

  9. 20191112 Spring Boot官方文档学习(4.3)

    4.3.Profiles Spring Profiles提供了一种隔离部分应用程序配置并使之仅在某些环境中可用的方法.任何@Component,@Configuration或@Configuratio ...

  10. Grafana配置文件

    配置文件位置 /usr/local/opt/grafana/share/grafana/default.ini /usr/local/etc/grafana/grafana.ini 配置文件调用顺序 ...