Linux学习笔记(7)Linux常用命令之压缩解压命令

(1)gzip

gzip命令用于压缩文件,英文原意为GNU zip,所在路径/bin/gzip,其语法格式为:

gzip [文件]

压缩后的文件格式为.gz。

例:将/etc目录下的services文件拷贝至/tmp目录,并采用gzip进行压缩。

[[email protected] tmp]# cp /etc/services services

[[email protected] tmp]# ls

services

[[email protected] tmp]# gzip services

[[email protected] tmp]# ls

services.gz

注:gzip只能压缩文件,无法压缩目录;gzip命令不保留源文件,上例就可以看出。

(2)gunzip

gunzip命令用于解压缩文件,英文原意为GNU unzip,所在路径为/bin/gunzip,其语法格式为:

gunzip [压缩文件]

例:解压缩新创建的压缩文件

[[email protected] tmp]# gunzip services.gz

[[email protected] 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目录进行打包。

[[email protected] tmp]# mkdir -p test/test1 test/test2

[[email protected] tmp]# tar -czvf test.tar.gz test

test/

test/test2/

test/test1/

[[email protected] tmp]# ls -l

total 636

-rw-r--r--. 1 root root 641020 Jan  1 22:17 services

drwxr-xr-x. 4 root root   4096 Jan  1 22:25 test

-rw-r--r--. 1 root root    134 Jan  1 22:26 test.tar.gz

tar解压缩的语法格式为:

tar -xzvf [压缩文件]

其中,-x选项表示解包,-v选项表示显示详细信息,-f选项表示指定解压文件,-z选项表示解压缩。

例:删除创建的test目录,然后解压缩test.tar.gz

[[email protected] tmp]# rm -rf test

[[email protected] tmp]# ls

services  test.tar.gz

[[email protected] tmp]# tar -xzvf test.tar.gz

test/

test/test2/

test/test1/

[[email protected] tmp]# ls

services  test  test.tar.gz

(4)zip

zip命令用于压缩文件或目录,所在路径为/usr/bin/zip,其语法格式为:

zip 选项[-r] [压缩后的文件名] [文件或目录]

其中,-r选项表示压缩目录,压缩后的文件格式为.zip。

例:将services文件进行zip压缩:

[[email protected] tmp]# zip services.zip services

  adding: services (deflated 80%)

[[email protected] tmp]# ls

services  services.zip  test  test.tar.gz

注:zip格式在Linux和Windows中均存在;压缩比并不是很高。

(5)unzip

unzip命令用于解压.zip格式的文件,所在路径为/usr/bin/unzip,其语法格式为:

unzip [压缩文件]

例:解压services.zip文件

[[email protected] 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选项即表示压缩为.bz2文件。

例:使用bzip2命令对services文件进行压缩,随后将test目录也进行压缩

[[email protected] tmp]# bzip2 -k services

[[email protected] tmp]# ls

services  services.bz2  services.zip  test  test.tar.gz

[[email protected] tmp]# tar -cjvf test.bz2 test

test/

test/test2/

test/test1/

[[email protected] tmp]# ls

services  services.bz2  services.zip  test  test.bz2  test.tar.gz

(7)bunzip2

bunzip2命令用于解压缩.bz2文件,所在路径为/usr/bin/bunzip2,其语法格式为:

bunzip2 选项[-k] [压缩文件]

其中-k表示解压缩后保留源文件。

使用tar命令也可以解压缩.bz2的文件,其格式为:

tar 选项[-xjvf] [压缩文件]

例:删除services文件和test文件夹,然后分别解压缩:

[[email protected] tmp]# rm -rf services test

[[email protected] tmp]# ls

services.bz2  services.zip  test.bz2  test.tar.gz

[[email protected] tmp]# bunzip2 services.bz2

[[email protected] tmp]# tar -xjvf test.bz2

test/

test/test2/

test/test1/

[[email protected] tmp]# ls

services  services.zip  test  test.bz2  test.tar.gz
时间: 2025-01-07 03:44:41

Linux学习笔记(7)Linux常用命令之压缩解压命令的相关文章

linux命令之——压缩解压命令

linux命令之——压缩解压命令 命令名称:gzip 命令英文原意:GUN zip 命令所在路径:/bin/gzip 执行权限:所有用户 语法:gzip[文件] 功能描述:压缩文件(且只能压缩文件,不保存原文件) 压缩文件格式:.gz 范例: 压缩  :gzip boduo                      压缩后的文件格式为 boduo.gz 解压缩:gunzip boduo.gz            或者(gzip -d boduo.gz) ====================

2016/8/19 Linux常用命令 : 帮助命令、用户管理命令、压缩解压命令

1.获取帮助信息:man man ls :获取 ls 命令的帮助信息 man services :查看配置文件services的帮助信息,直接加文件名称,不需要绝对路径 帮助: 1表示命令的帮助,5表示配置文件的帮助 man  1  passwd 2. 查看命令的介绍: whatis 3.产看配置文件信息:apropos  配置文件名称 3.获得Shell 内置命令的帮助信息 : help help umask :查看 umask 命令的帮助信息 4.查看命令的选项: 命令  --help 4.

linux学习笔记四:文件的打包与解压

linux笔记:linux常用命令-压缩解压命令

压缩解压命令:gzip(压缩文件,不保留原文件.这个命令不能压缩目录) 压缩解压命令:gunzip(解压.gz的压缩文件) 压缩解压命令:tar(打包压缩目录或者解压压缩文件.打包的意思是把目录打包成一个文件,不等同于压缩.tar命令可以在打包的同时进行压缩,得到.tar.gz文件) 压缩解压命令:zip(压缩文件或者目录,会保留原文件) 压缩解压命令:unzip(解压.zip的压缩文件) 压缩解压命令:bzip2(压缩文件) 压缩解压命令:bunzip2(解压.bz2的文件)

Linux下常见压缩解压命令

inux zip命令 zip -r myfile.zip ./* 将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzip unzip -o -d /home/sunny myfile.zip 把myfile.zip文件解压到 /home/sunny/ -o:不提示的情况下覆盖文件: -d:-d /home/sunny 指明将文件解压缩到/home/sunny目录下: 3.其他 zip -d myfile.zip smart.txt 删

Linux压缩解压命令全解

常用压缩格式 压缩格式: .zip..gz..bz2..tar.gz..tar.bz2..tar.xz 最常用的是.tar.gz格式和.tar.bz2格式 1.  zip命令 zip格式其实和windows的zip格式是一样的,也就是说可以和windows相互解压缩使用. 序列 命令 解释 1 zip filename.zip filename 压缩源文件 2 zip -r filename.zip filename 压缩源文件目录 3 unzip filename.zip 解压 2.  .gz

Linux压缩解压命令详细介绍(gizp、tag、zip、bzip2)

--------------------------------------压缩解压命令------------------------------- *windos可以解压所有linux系统的文件压缩包,但linux不一定能够全部解压windos的 一: gzip :压缩文件 ---  GUN zip    .gz文件格式 特点:1只能压缩文件,不能压缩目录 2不保留源文件 例子:gzip newfile   就会产生一个newfile.gz的一个文件包 gunzip :解压缩(或者用gzip

Linux下解包/打包,压缩/解压命令

.tar 解包:tar xvf FileName.tar 打包:tar cvf fileName.tar DirName tar.gz和.tgz 解压:tar zxvf FileName.tar.zip [-C DirName] 压缩:tar zcvf FileName.tar.zip DirName .tar.bz2 解压:tar jxvf FileName.tar.bz2 或tar -bzip xvf FileName.tar.bz2 压缩:tar jcvf FileName.tar.bz2

压缩解压命令小结

Linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通常都是以.tar结尾的.生成tar包后,就可以用其它的程序来进 行压缩了,所以首先就来讲讲tar命令的基本用法: tar命令的选项有很多(用man tar可以查看到),但常用的就那么几个选项,下面 来举例说明一下: # tar -cf all.tar *.jpg 这条命令是将所有.jpg的文件打成一个名为all.tar的包.-c是表示产生新的包 ,-f指定包的文件名. # tar -rf a