Linux文档压缩与打包

简介:
zip压缩工具
zip压缩包在Windows和Linux中比较常用,它可以压缩目录和文件,压缩目录时,需要指定目录下的文件
zip 1.txt.zip 1.txt 压缩文件并指明目录下的文件
unzip 1.txt.zip
[root@localhost d6z]# zip 1.txt.zip 1.txt 压缩文件
adding: 1.txt (deflated 73%)
[root@localhost d6z]# du -sh 1.txt.zip 查看压缩的情况
476K 1.txt.zip
[root@localhost d6z]# unzip 1.txt.zip 解压
Archive: 1.txt.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: 1.txt
[root@localhost d6z]# ls
1.txt 1.txt.zip 2.txt d6z test1 test2
tar打包工具
tar -cvf 123.tar 123
tar -cvf aming.tar 1.txt 123
tar -xvf aming.tar
tar -tf aming.tar
tar -cvf aming.tar --exclude 1.txt --exclude 2123
实验
准备
[root@localhost d6z]# cd /root 切换到root目录下
[root@localhost ~]# mkdir /tmp/8 创建一个目录
[root@localhost ~]# cd /tmp/8 切换到创建的目录下
[root@localhost 8]# mkdir test 创建目录
[root@localhost 8]# mv /tmp/1.txt test 移动一个文件到test目录下
打包
[root@localhost 8]# tar -cvf test.tar test 打包test目录
test/ 
test/1.txt
[root@localhost 8]# ls 打印当前目录清单
test test.tar
[root@localhost 8]# du -sh 查看目录大小
3.5M .
解包
[root@localhost 8]# tar -xvf test.tar test 解包
test/
test/1.txt
[root@localhost 8]# ls 打印当前的目录清单
test test.tar
备注:tar 打包和解包都会覆盖之前的文件
[root@localhost test]# tar -cvf test.tar 1.txt 2.txt 3.txt 打包目录和文件
1.txt
2.txt
3.txt
[root@localhost test]# tar -xvf test.tar 1.txt 2.txt 3.txt 解压目录和文件
1.txt 
2.txt
3.txt
[root@localhost 8]# tar -tf test.tar -tf 查看tar打包的文件
test/
test/test.tar
test/1.txt
test/2.txt
test/3.txt
[root@localhost 8]# tar -cvf test.tar --exclude 3.txt test -- exclude 过滤文件打包
test/
test/test.tar
test/1.txt
test/2.txt
tar打包并压缩
tar -zcvf 123.tar.gz 123 打包以gzip压缩
tar -zxvf 123.tar.gz 解压
tar -jcvf 123.tar.bz2 123 打包以bzip2压缩
tar -jxvf 123.tar.bz2 解压
tar -Jcvf 123.tar.xz 123 打包以xz压缩
tar -Jxvf 123.tar.xz 解压
[root@localhost 8]# tar -zcvf test.tar.gz test gzip压缩
test/
test/3.txt
test/test.tar
test/1.txt
test/2.txt
[root@localhost 8]# ls
2.txt test test.tar test.tar.gz
[root@localhost 8]# du -sh test
3.5M test
[root@localhost 8]# tar -zxvf test.tar.gz 解包
test/
test/3.txt
test/test.tar
test/1.txt
test/2.txt
备注:bzip xz 打包压缩同gzip操作方法一样
查看tar包压缩命令
-tf 适用所有的tar包压缩
[root@localhost 8]# tar -tf test.tar.xz 查看打包gzip压缩包
test/
test/3.txt
test/test.tar
test/1.txt
test/2.txt
[root@localhost 8]# tar -tf test.tar.gz
test/
test/3.txt
test/test.tar
test/1.txt
test/2.txt
[root@localhost 8]# tar -tf test.tar.bz2
test/
test/3.txt
test/test.tar
test/1.txt

test/2.txt


本文转自 yzllinux博客,原文链接:    http://blog.51cto.com/12947851/2058231    如需转载请自行联系原作者

相关文章
|
1月前
|
Shell Linux API
【Shell 命令集合 备份压缩 】Linux 解压缩文件 unzip命令 使用指南
【Shell 命令集合 备份压缩 】Linux 解压缩文件 unzip命令 使用指南
53 0
|
1月前
|
算法 Shell Linux
【Shell 命令集合 备份压缩 】Linux 处理lha格式 lha命令 使用指南
【Shell 命令集合 备份压缩 】Linux 处理lha格式 lha命令 使用指南
40 0
|
1月前
|
存储 监控 Shell
【Shell 命令集合 备份压缩 】Linux 备份文件系统 dump命令 使用指南
【Shell 命令集合 备份压缩 】Linux 备份文件系统 dump命令 使用指南
37 0
|
1月前
|
Shell Linux C语言
【Shell 命令集合 备份压缩 】Linux 归档和解档文件 cpio命令 使用指南
【Shell 命令集合 备份压缩 】Linux 归档和解档文件 cpio命令 使用指南
40 0
|
1月前
|
算法 Linux Shell
【Shell 命令集合 备份压缩 】Linux 压缩.Z文件 compress命令 使用指南
【Shell 命令集合 备份压缩 】Linux 压缩.Z文件 compress命令 使用指南
32 0
|
1月前
|
Shell Linux 编译器
【Shell 命令集合 备份压缩 】Linux 提取zip压缩文件的详细信息 zipinfo命令 使用指南
【Shell 命令集合 备份压缩 】Linux 提取zip压缩文件的详细信息 zipinfo命令 使用指南
34 0
|
1月前
|
存储 算法 Shell
【Shell 命令集合 备份压缩 】⭐⭐Linux 压缩和归档工具 zip命令 使用指南
【Shell 命令集合 备份压缩 】⭐⭐Linux 压缩和归档工具 zip命令 使用指南
36 0
|
1月前
|
存储 Shell Linux
【Shell 命令集合 备份压缩 】Linux 解码uuencode编码的文件 uudecode 命令 使用指南
【Shell 命令集合 备份压缩 】Linux 解码uuencode编码的文件 uudecode 命令 使用指南
31 0
|
1月前
|
安全 Shell Linux
【Shell 命令集合 备份压缩 】Linux将可执行文件压缩成gzip格式 gzexe命令 使用指南
【Shell 命令集合 备份压缩 】Linux将可执行文件压缩成gzip格式 gzexe命令 使用指南
38 0
|
1月前
|
算法 Shell Linux
【Shell 命令集合 备份压缩 】⭐Linux 压缩 恢复bzip2损坏数据 bzip2recover命令 使用指南
【Shell 命令集合 备份压缩 】⭐Linux 压缩 恢复bzip2损坏数据 bzip2recover命令 使用指南
33 0