摘要:本文主要学习了Linux的打包命令和压缩命令。

tar命令

tar命令可以用来进行打包和解打包,压缩和解压缩。

基本语法

打包和压缩的语法:

1 tar [选项] 源文件或目录

解打包和解压缩的语法:

1 tar [选项] 压缩包

选项说明

打包和压缩的选项:

1 -c:将多个文件或目录进行打包。
2 -v:显示打包文件的过程。
3 -f 文件名:指定打包的文件名。
4 -z:压缩和解压缩.tar.gz格式。
5 -j:压缩和解压缩.tar.bz2格式。

解打包和解压缩的选项:

1 -x:对tar包做解打包操作。
2 -v:显示解打包的过程。
3 -f 文件名:指定要解压的文件名。
4 -z:压缩和解压缩.tar.gz格式。
5 -j:压缩和解压缩.tar.bz2格式。
6 -t:只查看包中有哪些文件或目录,不做解打包操作。
7 -C 目录名:指定解打包位置。

使用举例

打包为 tar 格式的文件:

1 [root@localhost home]# tar -cvf hello.tar hello hello-hard hello-soft
2 hello
3 hello-hard
4 hello-soft
5 [root@localhost home]# ls
6 hello  hello-hard  hello-soft  hello.tar  test  test-soft
7 [root@localhost home]# 

压缩为 tar.gz 格式的文件:

1 [root@localhost home]# tar -zcvf test.tar.gz test test-soft
2 test/
3 test-soft
4 [root@localhost home]# ls
5 hello  hello-hard  hello-soft  hello.tar  test  test-soft  test.tar.gz
6 [root@localhost home]# 

解打包 tar 格式的文件:

1 [root@localhost home]# tar -xvf hello.tar
2 hello
3 hello-hard
4 hello-soft
5 [root@localhost home]# ls
6 hello  hello-hard  hello-soft  hello.tar  test.tar.gz
7 [root@localhost home]# 

解压缩 tar.gz 格式的文件:

1 [root@localhost home]# tar -zxvf test.tar.gz
2 test/
3 test-soft
4 [root@localhost home]# ls
5 hello  hello-hard  hello-soft  hello.tar  test  test-soft  test.tar.gz
6 [root@localhost home]# 

查看 tar 格式文件的内容:

1 [root@localhost home]# tar -tvf hello.tar
2 -rw-r--r-- root/root     10240 2019-07-11 01:28 hello
3 hrw-r--r-- root/root         0 2019-07-11 01:28 hello-hard 连接到 hello
4 lrwxrwxrwx root/root         0 2019-07-11 03:56 hello-soft -> hello
5 [root@localhost home]# 

查看 tar.gz 格式文件的内容:

1 [root@localhost home]# tar -ztvf test.tar.gz
2 drwxr-xr-x root/root         0 2019-07-11 01:14 test/
3 drwxr-xr-x root/root         0 2019-07-11 01:14 test-soft/
4 [root@localhost home]# 

zip命令

zip命令类似于Windows系统中的winzip压缩程序。

基本语法

1 zip [选项] 压缩包名 源文件或源目录列表

选项说明

1 -r:递归压缩目录,及将指定目录下的所有文件以及子目录全部压缩。
2 -m:将文件压缩之后,删除原始文件,相当于把文件移到压缩文件中。
3 -v:显示详细的压缩过程信息。
4 -q:在压缩的时候不显示命令的执行过程。
5 -压缩级别:压缩级别是从1~9的数字,-1代表压缩速度更快,-9代表压缩效果更好。
6 -u:更新压缩文件,即往压缩文件中添加新文件。

使用举例

 1 [root@localhost home]# ls2 hello  hello-hard  hello-soft  test  test-soft3 [root@localhost home]# zip hello.zip hello hello-hard 4   adding: hello (deflated 99%)5   adding: hello-hard (deflated 99%)6 [root@localhost home]# ls7 hello  hello-hard  hello-soft  hello.zip  test  test-soft8 [root@localhost home]# zip test.zip test test-soft9   adding: test/ (stored 0%)
10   adding: test-soft/ (stored 0%)
11 [root@localhost home]# ls
12 hello  hello-hard  hello-soft  hello.zip  test  test-soft  test.zip
13 [root@localhost home]#

unzip命令

unzip命令可以查看和解压缩zip文件。

基本语法

1 unzip [选项] 压缩包名

选项说明

1 -d 目录名:将压缩文件解压到指定目录下。
2 -n:解压时并不覆盖已经存在的文件。
3 -o:解压时覆盖已经存在的文件,并且无需用户确认。
4 -v:查看压缩文件的详细信息,包括压缩文件中包含的文件大小、文件名以及压缩比等,但并不做解压操作。
5 -t:测试压缩文件有无损坏,但并不解压。
6 -x 文件列表:解压文件,但不包含文件列表中指定的文件。

使用举例

 1 [root@localhost home]# ls2 hello.zip  test.zip3 [root@localhost home]# unzip -v hello.zip 4 Archive:  hello.zip5  Length   Method    Size  Cmpr    Date    Time   CRC-32   Name6 --------  ------  ------- ---- ---------- ----- --------  ----7    10240  Defl:N       99  99% 07-11-2019 01:28 dda39bf9  hello8    10240  Defl:N       99  99% 07-11-2019 01:28 dda39bf9  hello-hard9 --------          -------  ---                            -------
10    20480              198  99%                            2 files
11 [root@localhost home]# unzip hello.zip
12 Archive:  hello.zip
13   inflating: hello
14   inflating: hello-hard
15 [root@localhost home]# ls
16 hello  hello-hard  hello.zip  test.zip
17 [root@localhost home]# unzip -d zip test.zip
18 Archive:  test.zip
19    creating: zip/test/
20    creating: zip/test-soft/
21 [root@localhost home]# ls
22 hello  hello-hard  hello.zip  test.zip  zip
23 [root@localhost home]# ls zip
24 test  test-soft
25 [root@localhost home]#

以上就是良许教程网为各位朋友分享的Linux相关知识。

linux打包压缩命令相关推荐

  1. 【linux | 打包压缩命令】

    文章目录 前言 打包压缩 1. zip/unzip 2. gzip/gunzip 3. xz xz与gzip的区别 空间占用 时间对比 4. bzip2 前四个压缩工具总结 5. 打包命令--tar ...

  2. linux 打包/压缩命令详解及英文解释

    在linux中打包和压缩和分两步来实现的: 1. 打包/ 压缩 打包 打包是将多个文件归并到一个文件: tar -cvf etc.tar /etc <==仅打包,不压缩! -c :打包选项 全称 ...

  3. linux打包压缩命令汇总

    tar命令  [root@linux ~]# tar [-cxtzjvfpPN] 文件与目录 .... 参数: -c :建立一个压缩文件的参数指令(create 的意思): -x :解开一个压缩文件的 ...

  4. linux打包压缩命令有哪些,Linux压缩打包命令使用方法有哪些呢?

    tar命令 [root@linux ~]# tar [-cxtzjvfpPN] 文件与目录 .... 参数: -c :建立一个压缩文件的参数指令(create 的意思): -x :解开一个压缩文件的参 ...

  5. linux下的打包和解压缩命令,浅析Linux打包压缩解压缩命令大全(收藏)

    下面是小编日常收集整理的关于linux打包压缩解压缩命令大全,具体内容如下所述: tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar Dir ...

  6. Linux常用打包压缩命令

    简介 Linux 上常用的压缩/解压工具,介绍了zip.rar.tar的使用. 文件打包和压缩 Linux 上的压缩包文件格式,除了 Windows 最常见的*.zip.*.rar..7z 后缀的压缩 ...

  7. linux打包命令tgz,浅析Linux打包压缩解压缩命令大全(收藏)

    下面是小编日常收集整理的关于linux打包压缩解压缩命令大全,具体内容如下所述: tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar Dir ...

  8. linux tar 打包gzip,tar linux 打包 压缩 gzip 命令说明

    参数: -c  :建立一个压缩档案的参数指令(create 的意思): -x  :解开一个压缩档案的参数指令! -t  :查看 tarfile 里面的档案! 特别注意,在参数的下达中, c/x/t 仅 ...

  9. tar 打包压缩命令(linux压缩命令)

    tar 命令用于文件的打包或压缩,是最为常用的打包压缩命令,其语法格式如下: tar [选项] 文件名.tar.gz 源文件 tar -cvfz xxx.tar.gz source_file (tar ...

  10. 【Linux】打包压缩命令

    打包压缩命令 作用: 对文件进行打包.解包.压缩.解压 语法: tar [-zcxvf] fileName [files]包文件后缀为.tar表示只是完成了打包,并没有压缩包文件后缀为.tar.gz表 ...

最新文章

  1. 2021年大数据Spark(十四):Spark Core的RDD操作
  2. Oracle 查询转换之子查询展开
  3. CTO 比普通程序员强在哪?
  4. oracle存储日志
  5. SAP CRM Fiori应用如何启用Sales Office和Sales Group两个字段
  6. Python第十二章-多进程和多线程01-多进程
  7. Flutter AlertDialog弹框的基本使用、Flutter showDialog方法使用概述
  8. js performance
  9. 推荐几个很实用的网址
  10. 【学习笔记】C++面向对象高级开发-侯捷
  11. 算法提高 金明的预算方案
  12. Html-小米官网头部
  13. 鸿蒙系统小米电视,鸿蒙系统被曝光!首款鸿浩818芯片,华为智慧屏对标小米电视...
  14. TWS蓝牙耳机怎么挑选?值得买的蓝牙耳机推荐
  15. 软件开发、系统定制、小程序等怎么报价?
  16. Unity 制作图集
  17. 关于赚钱这件事情,一定要行动起来,别总是想而不做
  18. ROS的四种通信架构(转载)
  19. 回顾2019年度京东集团10件大事:不忘初心,坚定前行
  20. Chrome98和Chrome101的跨域变化,httpOPTIONS预检请求,私有网络访问限制

热门文章

  1. 药品计算机培训计划,_计算机培训学习计划范文
  2. 计算机子网掩码在线,IP地址计算器
  3. vue实现滑块滑动校验
  4. 爬取三个acm网站题库(neuqoj pku hdu)
  5. Python实战:个人贷款计算器
  6. android反编译工具推荐,Android反编译的工具集合
  7. 用微信名片制作软件打造专属的电子名片
  8. html5shiv版本,用html5shiv.js解决ie低版本浏览器支持html5标签
  9. 互亿无线短信平台接口java实现
  10. 计算机硬件或网络连接失败,Win10系统出现45错误代码:硬件设备未连接到计算机...