linux下压缩和打包的使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下压缩和打包的使用相关的知识,希望对你有一定的参考价值。

文件目录压缩/解压缩  


文件压缩/解压缩 ------ gzip/bzip2/xz


1) gzip *.gz 


压缩:


[[email protected] ~]# gzip /file/1.txt 


[[email protected] ~]# file /file/1.txt.gz 

/file/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Mon Apr 10 15:22:52 2017

 

解压缩:


[[email protected] ~]#  gzip -d /file/1.txt.gz



2) bzip2 *.bz2 


[[email protected] ~]# bzip2 /file/2.txt


[[email protected] ~]# file /file/2.txt.bz2 

/file/2.txt.bz2: bzip2 compressed data, block size = 900k

[[email protected] ~]# 


[[email protected] ~]# bzip2 -d /file/2.txt.bz2 



3) xz *.xz 


[[email protected] ~]# xz /file/3.txt 


[[email protected] ~]# file /file/3.txt.xz 

/file/3.txt.xz: XZ compressed data


[[email protected] ~]# xz -d /file/3.txt.xz 




创建打包文件 --- tar 


1) 创建打包文件    *.tar 


# tar cf 打包文件名称 源文件

c: create创建

f:file文件


[[email protected] ~]# tar cf /bak/file01.tar /file/



2) 解包 


# tar xf 打包文件名称 [-C 目录名称]


[[email protected] ~]# tar xf /bak/file01.tar 


[[email protected] ~]# tar xf /bak/file01.tar -C /tmp/



3) 查看包中的文件 


[[email protected] ~]# tar tvf /bak/file01.tar




调用gzip实现压缩/解压缩 


# tar czf 打包文件名称 源文件 


z:调用gzip 

[[email protected] ~]# tar czf /bak/etc02.tar.gz /etc/


[[email protected] ~]# tar czf /bak/etc-$(date +%F).tar.gz /etc/


解压缩: 


# tar xzf 打包文件名称 [-C 目录名称]


[[email protected] ~]# tar zxf /bak/etc02.tar.gz -C /tmp/




调用bzip2实现压缩/解压缩  


# tar cjf 打包文件名称 目录名称 


j:调用bzip2 

[[email protected] ~]# tar cjf /bak/etc03.tar.bz2 /etc/


解压缩: 


# tar xjf 打包文件名称 [-C 目录名称]


[[email protected] ~]# tar xjf /bak/etc03.tar.bz2 -C /tmp/




调用xz实现压缩/解压缩  


# tar cJf 打包文件名称 目录名称 


J:调用xz

[[email protected] ~]# tar cJf /bak/etc04.tar.xz /etc/


解压缩: 


# tar xJf 打包文件名称 [-C 目录名称]


[[email protected] ~]# tar xJf /bak/etc03.tar.xz -C /tmp/


本文出自 “lyw666” 博客,请务必保留此出处http://lyw666.blog.51cto.com/12823216/1957550

以上是关于linux下压缩和打包的使用的主要内容,如果未能解决你的问题,请参考以下文章

Linux打包压缩

linux下打包与压缩

Linux下打包压缩war和解压war包

linux下打包命令的使用

Linux下文件的打包与压缩(tar命令)

linux文件管理--压缩打包