0
点赞
收藏
分享

微信扫一扫

Linux战地日记—压缩解压命令


linux战地日记—压缩/解压

在windows和linux中都会有各种压缩包,所不同的是windows中使用winRAR可以解压所有格式的压缩文件,但对于Linux,每种格式的压缩文件都需要特定的解压命令。



一般在linux中有这几种压缩文件格式:

.gz

.zip

.tar.gz

.bz2

这些文件格式对应着相应的压缩/解压命令


注意点:


后缀含有.tar的是打包文件,.tar.gz后缀的是.gz压缩格式的打包文件。


gzip和bzip2只能压缩文件,不能压缩目录。解决方法是先使用tar命令将目录打包成打包文件。

zip是linux和windows通用的命令,即可打包文件也可打包目录,对于小型文件,建议使用此命令。


gzip命令 压缩文件



命令所在路径: /bin/gzip

压缩后文件格式:gz


注意:

1.gzip只能压缩文件,不能压缩命令。

2.不保留源文件。

gunzip命令 解压文件



效果等同于gzip -d


[bestcoder@localhost f1]$ ls
file1 file2
[bestcoder@localhost f1]$ gzip file2
[bestcoder@localhost f1]$ ls
file1 file2.gz
[bestcoder@localhost f1]$ gzip -d file2.gz
[bestcoder@localhost f1]$ ls
file1 file2




tar命令 打包目录



tar 选项[cvf] 打包后的文件名.tar.gz(建议) 目录

打包命令

-c 产生.tar打包文件

-v 显示详细信息

-f 指定压缩后的文件

-z 打包同时压缩(有些unix不可用)

注意:

1.有些老版本的unix未含有-z选项,此时可以先打包后压缩。

2.源文件未发生改变。

压缩后的文件格式: .tar.gz


解包命令

-x 解包.tar文件

-v 显示详细信息

-f 指定解压文件

-z 解压缩

[bestcoder@localhost f1]$ tar cvfz new.tar.gz dir1
dir1/
dir1/file1
[bestcoder@localhost f1]$ ls
dir1 file1 file2 new.tar.gz
[bestcoder@localhost f1]$ gunzip new.tar.gz //解压缩
[bestcoder@localhost f1]$ ls
dir1 file1 file2 new.tar
[bestcoder@localhost f1]$ tar -xf new.tar //解包
[bestcoder@localhost f1]$ ls
dir1 file1 file2 new.tar


zip命令 (linux和windows通用压缩文件格式)



注意:

1.可压缩文件也可压缩目录

2.压缩后保留原文件。

3.压缩后格式为.zip

bzip2命令



bzip2 选项[-k] [原文件]

-k 压缩后保留原文件

压缩后文件格式: .bz2

范例: $bzip2 -k file1


[bestcoder@localhost f1]$ bzip2 file2 //未保留原文件
[bestcoder@localhost f1]$ ls
dir1 file1 file2.bz2 newdir.zip newfile.zip new.tar
[bestcoder@localhost f1]$ bzip2 -k file1 //保留原文件
[bestcoder@localhost f1]$ ls
dir1 file1 file1.bz2 file2.bz2 newdir.zip newfile.zip new.tar



bunzip2命令



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

-k 解压缩后保留原文件


范例: $bunzip2 -k file1.bz2


[bestcoder@localhost f1]$ ls
dir1 file1.bz2 file2 file2.bz2 newdir.zip newfile.zip new.tar
[bestcoder@localhost f1]$ bunzip2 file1.bz2
[bestcoder@localhost f1]$ ls
dir1 file1 file2 file2.bz2 newdir.zip newfile.zip new.tar


举报

相关推荐

0 条评论