Linux学习笔记(7)Linux常用命令之压缩解压命令
(1)gzip
gzip命令用于压缩文件,英文原意为GNU zip,所在路径/bin/gzip,其语法格式为:
gzip [文件]
压缩后的文件格式为.gz。
例:将/etc目录下的services文件拷贝至/tmp目录,并采用gzip进行压缩。
[root@localhost tmp]# cp /etc/services services [root@localhost tmp]# ls services [root@localhost tmp]# gzip services [root@localhost tmp]# ls services.gz
注:gzip只能压缩文件,无法压缩目录;gzip命令不保留源文件,上例就可以看出。
(2)gunzip
gunzip命令用于解压缩文件,英文原意为GNU unzip,所在路径为/bin/gunzip,其语法格式为:
gunzip [压缩文件]
例:解压缩新创建的压缩文件
[root@localhost tmp]# gunzip services.gz [root@localhost tmp]# ls services
注:也可以使用gzip -d解压缩文件;gunzip执行后不保留源文件。
(3)tar
tar命令用于打包目录,所在路径为/bin/tar,其语法格式为:
tar 选项[-zcf] [压缩后的文件名] [目录]
其中,-c选项表示打包;-v选项表示显示详细信息,-f选项指定文件名,-z选项表示打包的同时进行压缩,压缩后的文件格式为.tar.gz。
例:在/tmp目录下创建test/test1和test/test2目录,然后对test目录进行打包。
[root@localhost tmp]# mkdir -p test/test1 test/test2 [root@localhost tmp]# tar -czvf test.tar.gz test test/ test/test2/ test/test1/ [root@localhost tmp]# ls -l total -rw-r--r--. root root Jan : services drwxr-xr-x. root root Jan : test -rw-r--r--. root root Jan : test.tar.gz
tar解压缩的语法格式为:
tar -xzvf [压缩文件]
其中,-x选项表示解包,-v选项表示显示详细信息,-f选项表示指定解压文件,-z选项表示解压缩。
例:删除创建的test目录,然后解压缩test.tar.gz
[root@localhost tmp]# rm -rf test [root@localhost tmp]# ls services test.tar.gz [root@localhost tmp]# tar -xzvf test.tar.gz test/ test/test2/ test/test1/ [root@localhost tmp]# ls services test test.tar.gz
(4)zip
zip命令用于压缩文件或目录,所在路径为/usr/bin/zip,其语法格式为:
zip 选项[-r] [压缩后的文件名] [文件或目录]
其中,-r选项表示压缩目录,压缩后的文件格式为.zip。
例:将services文件进行zip压缩:
[root@localhost tmp]# zip services.zip services adding: services (deflated %) [root@localhost tmp]# ls services services.zip test test.tar.gz
注:zip格式在Linux和Windows中均存在;压缩比并不是很高。
(5)unzip
unzip命令用于解压.zip格式的文件,所在路径为/usr/bin/unzip,其语法格式为:
unzip [压缩文件]
例:解压services.zip文件
[root@localhost tmp]# unzip services.zip Archive: services.zip replace services? [y]es, [n]o, [A]ll, [N]one, [r]ename:
源文件存在,解压时询问是否替换。
(6)bzip2
bzip2是gzip的升级版本,也用于压缩文件,所在路径为/usr/bin/bzip2,其语法格式为:
bzip2 选项[-k] [文件]
其中-k选项产生压缩文件后保留源文件。压缩后的文件格式为.bz2。
使用tar命令可以将目录保存为.bz2文件,其格式为:
tar 选项[-cjvf] [压缩后文件名] [目录]
其中-j选项即表示压缩为.tar.bz2文件。
例:使用bzip2命令对services文件进行压缩,随后将test目录也进行压缩
[root@localhost tmp]# bzip2 -k services [root@localhost tmp]# ls services services.bz2 services.zip test test.tar.gz [root@localhost tmp]# tar -cjvf test.tar.bz2 test test/ test/test2/ test/test1/ [root@localhost tmp]# ls services services.bz2 services.zip test test.tar.bz2 test.tar.gz
(7)bunzip2
bunzip2命令用于解压缩.bz2文件,所在路径为/usr/bin/bunzip2,其语法格式为:
bunzip2 选项[-k] [压缩文件]
其中-k表示解压缩后保留源文件。
使用tar命令也可以解压缩.bz2的文件,其格式为:
tar 选项[-xjvf] [压缩文件]
例:删除services文件和test文件夹,然后分别解压缩:
[root@localhost tmp]# rm -rf services test [root@localhost tmp]# ls services.bz2 services.zip test.bz2 test.tar.gz [root@localhost tmp]# bunzip2 services.bz2 [root@localhost tmp]# tar -xjvf test.tar.bz2 test/ test/test2/ test/test1/ [root@localhost tmp]# ls services services.zip test test.tar.bz2 test.tar.gz
Linux学习笔记(7)Linux常用命令之压缩解压命令的更多相关文章
- Linux常用命令6 压缩解压命令
.zip是Linux和Windows共有的压缩格式 1.压缩解压命令:gzip 命令英文原意:GNU zip 命令所在路径:/bin/gzip 执行权限:所有用户 语法: gzip [文件] ...
- Linux学习笔记之四————Linux常用命令之文件管理
Linux命令——文件管理相关命令 <1>查看文件信息:ls ls是英文单词list的简写,其功能为列出目录的内容,是用户最常用的命令之一,它类似于DOS下的dir命令. Linux文件或 ...
- linux笔记:linux常用命令-压缩解压命令
压缩解压命令:gzip(压缩文件,不保留原文件.这个命令不能压缩目录) 压缩解压命令:gunzip(解压.gz的压缩文件) 压缩解压命令:tar(打包压缩目录或者解压压缩文件.打包的意思是把目录打包成 ...
- Linux 学习笔记 5 文件的下载、压缩、解压、初步认识yum
写在前面 上节我们通过简单的几组命令,已经完全的实现了文件的移动.删除.更名.以及复制,我们最常用的基本玩法,本节将带着大家学习压缩.解压的相关步骤. Linux 学习笔记 4 创建.复制.移动.文件 ...
- [转帖]Linux学习笔记之rpm包管理功能全解
Linux学习笔记之rpm包管理功能全解 https://www.cnblogs.com/JetpropelledSnake/p/11177277.html rpm 的管理命令 之前学习过 yum 的 ...
- Linux常用命令——压缩解压命令
Linux常用命令——压缩解压命令 Linux gzip 描述:压缩文件 语法:gzip [文件名] 压缩后文件格式:.gz gunzip 描述:解压后缀为.gz的文件 语法:gunzip [文件名 ...
- linux中tar及压缩解压命令用法
把常用的tar解压命令总结下,当作备忘: tar 命令可以为Linux的文件和目录创建档案.利用 tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向 档案中加入新的文件.t ...
- 浅谈Linux下各种压缩 解压命令和压缩比率对比
Linux下压缩.解压命令五花八门,不像在windows下一个winrar打遍天下无敌手,清一色的.rar .zip格式. 比如,Linux下常用的tar tar.gz tar.bz2 .Z等等不一而 ...
- [Linux] 016 压缩解压命令
1. 压缩解压命令:gzip 命令名称:gzip 命令所在路径:/bin/gzip 执行权限:所有用户 语法:gzip [文件] 功能描述:压缩文件 压缩后文件的格式:.gz 补充: 解压 .rar ...
随机推荐
- 渲染物体到一张UITexture上
把这个脚本挂到一个Camera上 using UnityEngine; using System.Collections; [RequireComponent(typeof(Camera))] pub ...
- 8.nodejs权威指南--MongoDB
1. MongoDB var mongo = require('mongodb'); var host = '127.0.0.1'; var port = mongo.Connecton.DEFAUL ...
- 数据结构顺序表删除所有特定元素x
顺序表类定义: template<class T> class SeqList : { public: SeqList(int mSize); ~SeqList() { delete[] ...
- mybatis 获取自增ID
在Mybatis Mapper文件中添加属性“useGeneratedKeys”和“keyProperty”,其中keyProperty是Java对象的属性名,而不是表格的字段名. <inser ...
- HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛
题目链接 题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬 ...
- SQL Server 2008 R2 安装出错:Could not open key
安装Sql Server 2008 R2 企业版出现错误提示无法继续安装,错误提示为: Could not open key: UNKNOWN\Components\7ABFE44842C12B390 ...
- August 30th 2016 Week 36th Tuesday
If you keep on believing, the dreams that you wish will come true. 如果你坚定信念,就能梦想成真. I always believe ...
- August 18th 2016 Week 34th Thursday
Comedy is acting out optimism. 喜剧就是将乐观演绎出来. Being optimistic or pessimistic, that is all about your ...
- Mysql 分区
关于分区操作,可参考:http://lobert.iteye.com/blog/1955841 这篇文章写的还是比较全面的. 关于Linear hash说明,可参考:http://www.bug315 ...
- 55. Jump Game leetcode
55. Jump Game Total Accepted: 95819 Total Submissions: 330538 Difficulty: Medium Given an array of n ...