首页 > 编程知识 正文

解压zip命令,linux zip命令详解

时间:2023-05-03 23:41:35 阅读:17494 作者:2611

gip是linux上常见的压缩/解压缩工具,最常用的是*.gz格式的文件。 这里简单介绍一下其最常用的使用方法。

gzip(1)通用命令手册gzip(1)1)。

名字

gip、gunzip、zcat - compress or expand files

SYNOPSIS

gzip [-acdfhkllnnrtvv 19 ] [-- rsync able ] [-s suffix ] [ name . ]

gunzip [-acfhklnnrtvv ] [-s suffix ] [ name . ]

zcat [ -fhLV ] [ name . ]

选项

-c----stdout----to--stdout的结果将写入标准输出,原始文件保持不变

-d----decompress----uncompress解压缩

在-k --keep压缩或解压缩过程中保留原始文件

-r --recursive

-t --test检查压缩文件的完整性

-v --verbose显示每个文件的名称和压缩率

---fast----best取-1(最快)到-9(最高)之间的值,默认值为-6

例1、文件压缩

原始文件名为file1.txt,压缩后原始文件消失,压缩后文件名为file1.txt.gz

root @ Ubuntu :/tmp # ls-lfile1. *

- rw-r---r----1root root 12383865 aug 2108336008 file1. txt

root @ Ubuntu :/tmp # gzip file1. txt

root @ Ubuntu :/tmp # ls-lfile1. *

- rw-r---r----1root root 134416 aug 2108:08 file1. txt.gz

例2、文件解压缩

root @ Ubuntu :/tmp # gzip-dfile1. txt.gz

root @ Ubuntu :/tmp # ls-LH file1. *

- rw-r---r----1root root 12 maug 2108336008 file1. txt

例3 )压缩时,显示压缩率

root @ Ubuntu :/tmp # gzip-vfile1. txt

file1. txt :98.9 %-- replacedwithfile1. txt.gz

例4、用一个命令压缩多个文件,压缩后分别分离:

root @ Ubuntu :/tmp # gzip file1. txtfile2. txt

root@ubuntu:/tmp# ls -l

总体1348

- rw-r---r----1root root 134416 aug 2108:08 file1. txt.gz

- rw-r-- r-- 1根根根根392 aug 2108:15 file2. txt.gz

例5、压缩中,保持原文件

root @ Ubuntu :/tmp # gzip-kfile1. txt

root@ubuntu:/tmp# ls file1.*

文件1.txt file1. txt.gz

例6、压缩为标准输出

可以连接两个文件

root @ Ubuntu :/tmp # cat file1. txtfile2. txt|gzip foo.gz

或者

root @ Ubuntu :/tmp # gzip-cfile1. txtfile2. txt foo.gz

===================================

gzip

压缩后的格式为*.gz

此压缩方法无法保存原始文件; 且无法压缩目录

命令示例:

#压缩

[root@localhost tmp]# gzip buodo

[root@localhost tmp]# ls

buodo.gz

#解冻

[ root @ localhost tmp ] # gunzipbuodo.gz

[root@localhost tmp]# ls

博多

tar

命令选项:

使用-z(gzip ) gzip压缩/解压缩文件

使用-j(bzip2 ) bzip2压缩/解压缩文件

-详细报告-v(Verbose ) tar处理的文件信息

- c (创建)创建新的归档文件

-解压缩x (提取)文件或目录

使用- f (文件)归档文件或设备。 此选项通常是必需的。

命令示例:

#压缩

[ root @ localhost tmp ] # tar-zvcfbuodo.tar.gzbuodo

[ root @ localhost tmp ] # tar-jvcfbuodo.tar.BZ2buo do

#解冻

[ root @ localhost tmp ] # tar-zvxfbuodo.tar.gz

[ root @ localhost tmp ] # tar-jvxfbuodo.tar.bz2

zip

与gzip相比,1 )可以压缩目录; 2 )可以保留原文件

可选:

递归压缩- r (恢复)目录中的所有文件和目录

命令示例:

#文件压缩和解压缩

[ root @ localhost tmp ] # zipboduo.zipboduo

[ root @ localhost tmp ] # unzipboduo.zip

#压缩和解压缩目录

[ root @ localhost tmp ] # zip-rdemo.zip demo

添加: demo/(stored0% ) )。

adding:demo/test2/

adding:demo/test1/

添加: demo/test1/test4(stored0% ) )。

adding:demo/test3(stored0% ) )

[ root @ localhost tmp ] # unzip demo.zip

Archive: Demo.zip

创建: demo /

creating: Demo/Test2/

creating: Demo/Test1/

扩展: demo/test1/test 4

扩展: demo/test 3

bzip2

压缩后的格式:bz2

参数

生成-k压缩文件后,保留原始文件

命令示例

#压缩

[root@localhost tmp]# bzip2 boduo

[ root @ localhost tmp ] # bzip2-kboduo

#解冻

[ root @ localhost tmp ] # bunzip2 boduo.bz2

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。