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 :可以 ...
随机推荐
- vue学习笔记(二): 添加 element ui 插件
一.加载 ui element vue add element 加载过程及成功结果如下 > vue add element>
- Flutter 你需要知道的那些事 01
公众号「AndroidTraveler」首发. 1. width 属性 对于设置控件宽度填充父控件这件事情,在 Android 里面,只需要设置 MATCH_PARENT 即可. 但是在 Flutte ...
- 程序卡在 while(SPI_I2S_GetFlagStatus(W5500_SPI, SPI_I2S_FLAG_TXE) == RESET) 处
stm32 SPI1,发现程序卡在 while(SPI_I2S_GetFlagStatus(W5500_SPI, SPI_I2S_FLAG_TXE) == RESET); 解决方式: 1.检查RCC时 ...
- 基于file上传文件的并发上传(多个文件一起上传到后台并把数据存储的同一条数据中,如 数据库字段videopath,imge。前台发送来的文件file1,file2。 videopath=file1,imge=file2)
前台代码: <div class="tab-content"> <dl> <dt>所属栏目</dt> <dd> < ...
- python中Socket的使用
说明 前一段时间学习python网络编程,完成简单的通过python实现网络通信的功能.现在,将python中Socket 通信的基本实现过程做一个记录备份. Socket通信 python 中的so ...
- Python目录和文件处理总结
1.判断目录是否存在.判断文件是否存在.创建目录.重命名目录或文件 import os #获取当前目录路径: E:\Work\Projects\python print(os.getcwd()) #判 ...
- 一文解读Spring全家桶 (转)
Spring框架自2002年诞生以来一直备受开发者青睐,它包括SpringMVC.SpringBoot.Spring Cloud.Spring Cloud Dataflow等解决方案.有人亲切的称之为 ...
- SRDC - ORA-22924 or ORA-1555 on LOB data: Checklist of Evidence to Supply (Doc ID 1682707.1)
SRDC - ORA-22924 or ORA-1555 on LOB data: Checklist of Evidence to Supply (Doc ID 1682707.1) Action ...
- Nginx的负载均衡算法、lvs的负载均衡算法
NGINX: 官方默认的算法: RR:轮询 weight:权重 ip_hash:配置此项后weight项失效 第三方模块: fair:根据后端服务器的繁忙程度 url_hash:如果客户端访问的url ...
- [PHP] 新版本PHP7.4与新版本MySQL8认证问题
mysql8的默认密码加密方式是caching_sha2_password,PHP7.4连接mysql的加密方式也为caching_sha2_password,这个地方要注意. 当为了兼容旧版的客户端 ...