Linux常用的压缩和解压命令gzip,gunzip,tar,zip, unzip和bzip2,bunzip2
Linux常用的压缩和解压命令
1、压缩解压gzip和gunzip
特点:
压缩比例大概为6:1
该命令只能压缩文件,不能压缩目录
压缩或者解压后不保留源文件
压缩示例:gzip 需要压缩的文件
解压示例gunzip xx.gz 或者gzip -d xx.gz
[root@localhost fengmin]# ll
total 656
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
[root@localhost fengmin]# gzip services
[root@localhost fengmin]# ll
total 136
-rw-r--r--. 1 root root 136088 Nov 4 10:16 services.gz # 压缩比例大概是6:1[root@localhost fengmin]# ll
total 656
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
drwxr-xr-x. 2 root root 23 Nov 4 10:18 test
[root@localhost fengmin]# gzip test # 不能压缩目录
gzip: test is a directory -- ignored
2、压缩解压命令tar
打包目录或文件,如果参数不带-z,就是只打包不压缩。压缩后的文件格式.tar或者.tar.gz
打包格式:tar 选项[-zcf] 压缩后的文件名 目录
-c 打包
-v 显示详细的打包信息
-f 指定压缩后的文件名
-z 打包同时压缩
-x 解压
解包格式:tar
也可以分两步打包和压缩,tar -cvf xx.tar xx 然后再gzip xx.tar,生成的就是xx.tar.gz
# 一步到位,打包加压缩
[root@localhost fengmin]# ll
total 656
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
drwxr-xr-x. 2 root root 23 Nov 4 10:18 test
[root@localhost fengmin]# tar -cvzf test.tar.gz test
test/
test/hello.txt# 分两步,先打包再压缩
[root@localhost fengmin]# ll
total 656
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
drwxr-xr-x. 2 root root 23 Nov 4 10:18 test
[root@localhost fengmin]# tar -cvf test.tar test/
test/
test/hello.txt
[root@localhost fengmin]# ll
total 668
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
drwxr-xr-x. 2 root root 23 Nov 4 10:18 test
-rw-r--r--. 1 root root 10240 Nov 4 10:43 test.tar
[root@localhost fengmin]# gzip test.tar
[root@localhost fengmin]# ll
total 660
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
drwxr-xr-x. 2 root root 23 Nov 4 10:18 test
-rw-r--r--. 1 root root 154 Nov 4 10:43 test.tar.gz# 解压
[root@localhost fengmin]# ll
total 1320
-rw-r--r--. 1 root root 670293 Nov 4 10:16 services
-rw-r--r--. 1 root root 675840 Nov 4 10:49 services.tar
drwxr-xr-x. 2 root root 23 Nov 4 10:18 test
-rw-r--r--. 1 root root 145 Nov 4 10:46 test.tar.gz
[root@localhost fengmin]# tar -zxvf test.tar.gz
test/
test/hello.txt
3、压缩解压命令zip
压缩文件或目录。linux和window都支持的格式
zip 选项[-r] 压缩后文件名 文件或者目录
-r 压缩目录 (不带-r表示压缩文件)
unzip xxx.zip 解压文件
[root@localhost fengmin]# ll
total 4
-rw-r--r--. 1 root root 75 Nov 4 10:57 hello.txt
drwxr-xr-x. 2 root root 19 Nov 4 10:56 test
[root@localhost fengmin]# zip hello.zip hello.txt # 压缩文件adding: hello.txt (deflated 77%)
[root@localhost fengmin]# ll
total 8
-rw-r--r--. 1 root root 75 Nov 4 10:57 hello.txt
-rw-r--r--. 1 root root 185 Nov 4 10:57 hello.zip
drwxr-xr-x. 2 root root 19 Nov 4 10:56 test
[root@localhost fengmin]# zip -r test.zip test/ # 压缩目录,要带上-r参数,否则就是压了一个空目录testadding: test/ (stored 0%)adding: test/hi.py (stored 0%)
[root@localhost fengmin]# ll
total 12
-rw-r--r--. 1 root root 75 Nov 4 10:57 hello.txt
-rw-r--r--. 1 root root 185 Nov 4 10:57 hello.zip
drwxr-xr-x. 2 root root 19 Nov 4 10:56 test
-rw-r--r--. 1 root root 308 Nov 4 10:58 test.zip
4、压缩解压命令bzip2和bunzip2
和gzip命令的区别就是多了-k参数,可以保留源文件,并且这个bzip2的压缩比惊人,压缩大文件推荐使用bzip2压缩。bzip2命令也是不能压缩目录啊,只能压缩文件
bzip2 选项[-k] [文件]
-k 产生压缩文件后保留源文件
压缩后文件格式.bz2
配合tar打包命令使用就是用-j参数
解压命令bunzip2 -k xx.bz2 解压,-k代表保留源文件
[root@localhost fengmin]# bzip2 -k hello.txt
[root@localhost fengmin]# ll
total 8
-rw-r--r--. 1 root root 75 Nov 4 10:57 hello.txt
-rw-r--r--. 1 root root 50 Nov 4 10:57 hello.txt.bz2
drwxr-xr-x. 2 root root 19 Nov 4 10:56 test
[root@localhost fengmin]# bzip2 -k test/ # 不能压缩目录
bzip2: Input file test/ is a directory[root@localhost fengmin]# ll
total 8
-rw-r--r--. 1 root root 75 Nov 4 10:57 hello.txt
-rw-r--r--. 1 root root 50 Nov 4 10:57 hello.txt.bz2
drwxr-xr-x. 2 root root 19 Nov 4 10:56 test
[root@localhost fengmin]# tar -cjf test.tar.bz2 test/ # -j参数代表bzip2压缩。解压是tar -xjf
[root@localhost fengmin]# ll
total 12
-rw-r--r--. 1 root root 75 Nov 4 10:57 hello.txt
-rw-r--r--. 1 root root 50 Nov 4 10:57 hello.txt.bz2
drwxr-xr-x. 2 root root 19 Nov 4 10:56 test
-rw-r--r--. 1 root root 140 Nov 4 11:13 test.tar.bz2
Linux常用的压缩和解压命令gzip,gunzip,tar,zip, unzip和bzip2,bunzip2相关推荐
- linux笔记:压缩解压命令gzip,gunzip,tar,zip,unzip,bzip2,bunzip2
命令名称:gzip 功能:压缩文件 命令所在路径:/bin/gzip 用法:gzip 文件 压缩后文件格式:.gz 其他: 压缩后不保留原文件: 只能压缩文件,不能压缩目录 命令名称:gunzip 功 ...
- Linux常用文件压缩/解压命令格式大全(tar、gzip、bzip2、zip、compress、cpio、compress、dd)建议收藏
Linux常用文件压缩/解压命令格式大全 1. tar 2. gzip 3. bzip2 4. zip 5. compress 6. cpio 7.dd 1. tar 打包备份后的文件包缀:.tar ...
- linux下的压缩和解压命令
1.gzip命令 //用于压缩文件 基本语法: gzip 文件名//压缩成gz后缀的文件 例子: 将/home/hhhh下面的Hello.java文件进行压缩 语法:gzip /home/hhhh/H ...
- Linux文件的压缩和解压命令tar
压缩文件扩展名 打包并压缩文件 tar的参数 语法:tar [参数] 压缩包名 一个或多被打包的文件 功能 作用 压缩一个或多个文件 -c 必须,创建一个压缩包 -v 可选,显示压缩的详细信息 -z ...
- linux 如何打包分区文件,Linux基础------文件打包解包---tar命令,文件压缩解压---命令gzip,vim编辑器创建和编辑正文件,磁盘分区/格式化,软/硬链接...
作业一: 1)将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cat /etc/passwd /etc/group > /1.txt 2)将用户信息数据库文件和用户 ...
- Linux 常用的压缩与解压缩命令详解
Linux 常用的压缩与解压缩命令有:tar.gzip.gunzip.bzip2.bunzip2.compress .uncompress. zip. unzip.rar.unrar 等. tar 最 ...
- 【Linux基础】压缩和解压
Linux 常用的压缩与解压文件类型:.tar,.gz..tar.gz,.bz2..tar.bz2,.Z..tar.Z,.zip,.rar等. Linux 常用的压缩与解压缩命令有:tar,gzip. ...
- linux ftp 解压缩命令,常用五种Linux环境中的压缩和解压命令示范 | OPS技术联盟
我们在使用云服务器的时候,压缩命令是常用的,虽然我们通过FTP工具慢慢将文件拖动到本地,但是如果我们的文件比较大,甚至有遇到文件几个G的,如果慢慢的拖动下来可能担心文件丢失或者不完整,最为是一个个下载 ...
- Linux中压缩和解压(gzip压缩/gunzip解压)(zip压缩/unzip解压)(tar打包解压)
文章目录 Linux中压缩和解压(gzip压缩/gunzip解压)(zip压缩/unzip解压)(tar打包解压) 一.gzip压缩 / gunzip解压 1.命令 2.注意 3.案例 4.常用 二. ...
最新文章
- AI一分钟 | 搜狗王小川:今年重点战略是输入法升级和发展机器翻译;北京无人驾驶试验场下半年正式运营
- 央行发布论文:区块链能做什么,不能做什么?
- Linux查看端口号是否使用
- 016_css()方法
- selenium容易忽视的知识点
- 【渝粤教育】国家开放大学2018年春季 3819-21T燃气安全管理 参考试题
- 数据绑定以及Container.DataItem几种方式与使用方法分析
- 阿里巴巴Java开发文档2020版学习-代码格式
- html提交表单原理,HTML5之Form 表单理论
- 激光雷达是什么?为什么移动机器人必不可少?
- 机器学习实战(4)——训练模型
- JavaEE与云服务知识概括
- DialogFragment中通过dataBinding绑定View,设置点击事件无效,通过getWindow设置dialog位置和大小无效。
- k8s源码分析 pdf_我是怎么阅读kubernetes源代码的?
- iOS开发人员必看的精品资料(100个)(转)
- [php-代码审计]百家cms4.14
- 数据库连接池druid 的jar包官网下载-最新版下载
- PCTA考试经验分享
- ASO外的App推广方式有这些
- AUTOSAR开发技术手册
热门文章
- android 如何启动浏览器
- raid读写速度对比_RAID5和RAID10读写性能哪个更好些?
- Android app 去除顶部蓝色导航栏(Action Bar
- 使用Fireworks 8制作网页效果图2-生成网页[原创教程]
- 设计分享|单片机8路抢答器
- 马斯克解释星际飞船原型测试失败:操作失误是主因
- 记录一下Jetson突然无法识别csi219相机笔记
- 仙剑五手游服务器维护,新仙剑奇侠传游戏进不去怎么办 游戏进不去解决方法...
- 06注解驱动的入门案例
- 【游戏介绍】aiwi3D疯狂平衡球