压缩格式 | 压缩命令 | 解压命令 |
---|---|---|
.gz | gzip | gunzip / gzip -d |
.tar | tar -cf | tar -xf |
.tar.gz | tar -zcf | tar -zxf |
.zip | zip /zip -r | unzip |
.bz2 | bzip2 | bunzip2 |
.tar.bz2 | tar -cjf | tar -xjf |
gzip
压缩文件,不保留源文件,不能压缩目录gunzip
解压.gz格式的压缩文件 gzip -d 也能解压文件tar
压缩
-v 压缩详情 -c 打包 -f 指定文件 -z 打包的同时压缩
[root@localhost tmp]# tar -zcvf file.tar.gz file* file001 file002 [root@localhost tmp]# ls dire file001 file002 file.tar.gz [root@localhost tmp]#
解压
-x 解包
[root@localhost tmp]# ls dire file.tar.gz [root@localhost tmp]# tar -zxf file.tar.gz [root@localhost tmp]# ls dire file001 file002 file.tar.gz
zip
压缩比例较低
-r 压缩目录
[root@localhost tmp]# ls direc1 file001.txt file002.txt file.txt svi [root@localhost tmp]# zip f.zip file.txt adding: file.txt (stored 0%) [root@localhost tmp]# ls direc1 file001.txt file002.txt file.txt f.zip svi [root@localhost tmp]# zip -r dir.zip direc1 adding: direc1/ (stored 0%) adding: direc1/dfile (stored 0%) adding: direc1/dfile2 (stored 0%) [root@localhost tmp]# ls direc1 dir.zip file001.txt file002.txt file.txt f.zip svi
解压
../../article/20220623/file.html
bzip2
压缩比比较好,建议使用
-k 保留源文件