Linux打包和压缩——管理打包和压缩的命令
Linux打包和压缩——管理打包和压缩的命令
摘要:本文主要学习了Linux的打包命令和压缩命令。
tar命令
tar命令可以用来进行打包和解打包,压缩和解压缩。
基本语法
打包和压缩的语法:
tar [选项] 源文件或目录
解打包和解压缩的语法:
tar [选项] 压缩包
选项说明
打包和压缩的选项:
-c:将多个文件或目录进行打包。
-v:显示打包文件的过程。
-f 文件名:指定打包的文件名。
-z:压缩和解压缩.tar.gz格式。
-j:压缩和解压缩.tar.bz2格式。
解打包和解压缩的选项:
-x:对tar包做解打包操作。
-v:显示解打包的过程。
-f 文件名:指定要解压的文件名。
-z:压缩和解压缩.tar.gz格式。
-j:压缩和解压缩.tar.bz2格式。
-t:只查看包中有哪些文件或目录,不做解打包操作。
-C 目录名:指定解打包位置。
使用举例
打包为 tar 格式的文件:
[root@localhost home]# tar -cvf hello.tar hello hello-hard hello-soft
hello
hello-hard
hello-soft
[root@localhost home]# ls
hello hello-hard hello-soft hello.tar test test-soft
[root@localhost home]#
压缩为 tar.gz 格式的文件:
[root@localhost home]# tar -zcvf test.tar.gz test test-soft
test/
test-soft
[root@localhost home]# ls
hello hello-hard hello-soft hello.tar test test-soft test.tar.gz
[root@localhost home]#
解打包 tar 格式的文件:
[root@localhost home]# tar -xvf hello.tar
hello
hello-hard
hello-soft
[root@localhost home]# ls
hello hello-hard hello-soft hello.tar test.tar.gz
[root@localhost home]#
解压缩 tar.gz 格式的文件:
[root@localhost home]# tar -zxvf test.tar.gz
test/
test-soft
[root@localhost home]# ls
hello hello-hard hello-soft hello.tar test test-soft test.tar.gz
[root@localhost home]#
查看 tar 格式文件的内容:
[root@localhost home]# tar -tvf hello.tar
-rw-r--r-- root/root -- : hello
hrw-r--r-- root/root -- : hello-hard 连接到 hello
lrwxrwxrwx root/root -- : hello-soft -> hello
[root@localhost home]#
查看 tar.gz 格式文件的内容:
[root@localhost home]# tar -ztvf test.tar.gz
drwxr-xr-x root/root -- : test/
drwxr-xr-x root/root -- : test-soft/
[root@localhost home]#
zip命令
zip命令类似于Windows系统中的winzip压缩程序。
基本语法
zip [选项] 压缩包名 源文件或源目录列表
选项说明
-r:递归压缩目录,及将指定目录下的所有文件以及子目录全部压缩。
-m:将文件压缩之后,删除原始文件,相当于把文件移到压缩文件中。
-v:显示详细的压缩过程信息。
-q:在压缩的时候不显示命令的执行过程。
-压缩级别:压缩级别是从1~9的数字,-1代表压缩速度更快,-9代表压缩效果更好。
-u:更新压缩文件,即往压缩文件中添加新文件。
使用举例
[root@localhost home]# ls
hello hello-hard hello-soft test test-soft
[root@localhost home]# zip hello.zip hello hello-hard
adding: hello (deflated %)
adding: hello-hard (deflated %)
[root@localhost home]# ls
hello hello-hard hello-soft hello.zip test test-soft
[root@localhost home]# zip test.zip test test-soft
adding: test/ (stored %)
adding: test-soft/ (stored %)
[root@localhost home]# ls
hello hello-hard hello-soft hello.zip test test-soft test.zip
[root@localhost home]#
unzip命令
unzip命令可以查看和解压缩zip文件。
基本语法
unzip [选项] 压缩包名
选项说明
-d 目录名:将压缩文件解压到指定目录下。
-n:解压时并不覆盖已经存在的文件。
-o:解压时覆盖已经存在的文件,并且无需用户确认。
-v:查看压缩文件的详细信息,包括压缩文件中包含的文件大小、文件名以及压缩比等,但并不做解压操作。
-t:测试压缩文件有无损坏,但并不解压。
-x 文件列表:解压文件,但不包含文件列表中指定的文件。
使用举例
[root@localhost home]# ls
hello.zip test.zip
[root@localhost home]# unzip -v hello.zip
Archive: hello.zip
Length Method Size Cmpr Date Time CRC- Name
-------- ------ ------- ---- ---------- ----- -------- ----
Defl:N % -- : dda39bf9 hello
Defl:N % -- : dda39bf9 hello-hard
-------- ------- --- -------
% files
[root@localhost home]# unzip hello.zip
Archive: hello.zip
inflating: hello
inflating: hello-hard
[root@localhost home]# ls
hello hello-hard hello.zip test.zip
[root@localhost home]# unzip -d zip test.zip
Archive: test.zip
creating: zip/test/
creating: zip/test-soft/
[root@localhost home]# ls
hello hello-hard hello.zip test.zip zip
[root@localhost home]# ls zip
test test-soft
[root@localhost home]#
Linux打包和压缩——管理打包和压缩的命令的更多相关文章
- CentOS(十)--与Linux文件和目录管理相关的一些重要命令②
在结束了第二期的广交会实习之后,又迎来了几天休闲的日子,继续学习Linux.在上一篇随笔 Linux学习之CentOS(十七)--与Linux文件和目录管理相关的一些重要命令① 中,详细记录了与Lin ...
- CentOS(九)--与Linux文件和目录管理相关的一些重要命令①
接上一篇文章,实际生产过程中的目录管理一定要注意用户是root 还是其他用户. 一.目录与路径 1.相对路径与绝对路径 因为我们在Linux系统中,常常要涉及到目录的切换,所以我们必须要了解 & ...
- Linux用户和权限——管理用户和用户组的命令
Linux用户和权限——管理用户和用户组的命令 摘要:本文主要学习了在Linux系统中管理用户和用户组的命令. useradd命令 useradd命令可以用来创建新用户. 基本语法 useradd [ ...
- Linux目录和文件——管理目录和文件的命令
Linux目录和文件——管理目录和文件的命令 摘要:本文主要学习了Linux系统中关于目录和文件的操作. cd命令 cd命令用来切换工作目录,是Change Directory的缩写. 基本语法 cd ...
- Linux系统的日志管理、时间同步、延迟命令at
方便查看和管理 /var/log/messages ?系统服务及日志,包括服务的信息,报错等等 /var/log/secure ? ? ? ? 系统认证信息日志 /var/log/maillog ? ...
- CentOS系统文件和目录管理相关的一些重要命令
我们都知道,在Linux系统中,基本上任何我们需要做的事都可以通过输入命令来完成,所以在Linux系统中命令非常的多,我们不可能也没必要记住所有的这些命令,但是对于一些常用的命令我们还是必须要对其了如 ...
- 鸟哥的linux私房菜 - 第5/6/7/9章(在线求助 man page、Linux档案权限与目录配置、Linux档案与目录管理、压缩与打包)
第五章.在线求助 man page X window与文本模式的切换 Ctrl+Alt+F1~F6:文字接口登入tty1~tty6终端机: Ctrl+Alt+F7:图形接口桌面. 注销当前用户:exi ...
- 07.进程管理+作业控制+文件查找与压缩+文件压缩与打包+tar打包解包+NFS
进程管理 程序放在磁盘上叫文件,把它复制到内存,并在cpu运行,就叫进程, 进程多少也反映当前运行程序的多少 进程在系统中会为每个进程生成一个进程号,在所有的进程中有一个特殊进程即init进程, 它是 ...
- Linux系统常见的压缩与打包
1.gzip, zcat [root@linux ~]# gzip [-cdt#] 檔名参数: -c :将压缩的数据输出到屏幕上,可透过数据流重导向来处理: -d :解压缩的参数: -t :可以 ...
随机推荐
- PDF怎么转换为CAD文件?这两种方法你的会
在日常的办公中,我们最常见的文件格式就是PDF格式的,因为PDF文件的安全性是比较高的,可以防止不小心触碰到键盘修改文件内容,而且PDF文件便于进行文件的传输.但是有时候也需要将PDF转换成CAD,那 ...
- echarts水球图编写
// 前提条件 需要引入这个插件<script src="./echarts-liquidfill.min.js"></script> // 代码 let ...
- [20190929]bash使用bc计算的相关问题.txt
[20190929]bash使用bc计算的相关问题.txt --//快放假没什么事情,使用bash写一些小程序,转化number到oracle number编码,使用bc计算功能,发现一些小问题--/ ...
- Angular 学习笔记(三)
调试时抓取作用域: 1.右键选取审查元素,调出 debugger(或按 F12) 2.调试器允许用变量 $0 来获取当前选取的元素 3.在 console 中执行 angular.element($0 ...
- 网络流(2)——用Ford-Fullkerson算法寻找最大流
寻找最大流 在大规模战争中,后勤补给是重中之重,为了尽最大可能满足前线的物资消耗,后勤部队必然要充分利用每条运输网,这正好可以用最大流模型解决.如何寻找一个复杂网络上的最大流呢? 直觉上的方案 一种直 ...
- gn gen ninja
- luoguP4113 [HEOI2012]采花
经典颜色问题推荐博文 https://www.cnblogs.com/tyner/p/11519506.html https://www.cnblogs.com/tyner/p/11616770.ht ...
- c# 第37节 接口的实现与继承
本节内容: 1:接口继承注意 2:开发封闭原则: 3:实例解释接口的作用 1:接口继承注意 接口的继承: :类继承具有单根性,接口可多重继承: :接口继承多个接口的时候,派生接口名与父接口用冒号隔开, ...
- angular父子组件传值和ngOnChanges的使用
父组件中定义: public detailbaseinfo = {}; //详情基本信息 其中detailbaseinfo 数据会通过请求获取 父组件传值给子组件如下: 子组件接收父组件传值 imp ...
- CF1178 F1 Short Colorful Strip
题目链接 题意 有个长度为\(m\)公分的布,要在上面每公分都染上颜色,整块布染恰好\(n(n=m)\)种颜色.颜色标号从\(1\)到\(n\).染色需遵循: 1.从颜色\(1\)到颜色\(n\)依次 ...