Linux 压缩归档总结
2015-09-23 11:57
791 查看
linux压缩有文件, 目录压缩和归档
文件压缩种类:gzip, bzip2, xz
目录压缩:zip
归档:tar
各种文件压缩的命令都是实现下面的几个功能, 只是语法略有不同
gzip:
文件后缀: gz
压缩: gzip 文件, 删除原文件
bzip2文件后缀: bz2压缩: bzip2 文件, 会删除原文件解压: bunzip2 压缩文件, 会删除压缩文件保留原文件压缩: bzip2 -k 原文件
xz文件后缀: xz压缩: xz 文件, 会删除原文件解压: unxz 压缩文件, 会删除压缩文件保留原文件压缩: xz -k 源文件在压缩包内直接查看文件: xzcat 压缩文件
这几个命令的压缩比分别是
xz>bzip2>gzip
目录压缩zip
特殊用法: 1. 需要自己制定压缩后文件, 2压缩后原文件不会被删除 3 可以单独压缩文件
格式: zip 压缩后文件.zip 原文件
归档
创建归档
格式: tar cf 归档文件.tar 要归档的所有文件夹或文件
不用像zip,指定目录内所有文件
展开归档, 到当前目录, 不会删除压缩文件
tar xf tar文件
查看归档内文件
tar -tf tar文件
归档后压缩调用
压缩并归档
格式:tar -zcf 文件.tar.gz 文件
-z可替换其他压缩格式, 后缀也要有相应修改
-z: gzip, -j: bzip2, -J: xz
t格式 ar xf 压缩并归档后的文件
文件压缩种类:gzip, bzip2, xz
目录压缩:zip
归档:tar
各种文件压缩的命令都是实现下面的几个功能, 只是语法略有不同
gzip:
文件后缀: gz
压缩: gzip 文件, 删除原文件
[root@centos test]# ll total 192 -rw-------. 1 root root 193746 Sep 23 12:05 test01 [root@centos test]# gzip test01 [root@centos test]# ll total 32 -rw-------. 1 root root 29378 Sep 23 12:05 test01.gz解压: gunzip 压缩文件, 删除压缩文件
[root@centos test]# gunzip test01.gz [root@centos test]# ll total 192 -rw-------. 1 root root 193746 Sep 23 12:05 test01保留原文件压缩: gzip -c 文件 > 压缩后文件
[root@centos test]# gzip -c test01 > test02.gz [root@centos test]# ll total 224 -rw-------. 1 root root 193746 Sep 23 12:05 test01 -rw-r--r--. 1 root root 29378 Sep 23 13:24 test02.gz在压缩包内直接查看文件 zcat 压缩文件
[root@centos test]# zcat test02.gz | less
bzip2文件后缀: bz2压缩: bzip2 文件, 会删除原文件解压: bunzip2 压缩文件, 会删除压缩文件保留原文件压缩: bzip2 -k 原文件
[root@centos test]# bzip2 -k test02 [root@centos test]# ll total 212 -rw-r--r--. 1 root root 193746 Sep 23 13:24 test02 -rw-r--r--. 1 root root 19565 Sep 23 13:24 test02.bz2在压缩包内直接查看文件: bzcat 压缩文件
xz文件后缀: xz压缩: xz 文件, 会删除原文件解压: unxz 压缩文件, 会删除压缩文件保留原文件压缩: xz -k 源文件在压缩包内直接查看文件: xzcat 压缩文件
这几个命令的压缩比分别是
xz>bzip2>gzip
目录压缩zip
特殊用法: 1. 需要自己制定压缩后文件, 2压缩后原文件不会被删除 3 可以单独压缩文件
格式: zip 压缩后文件.zip 原文件
[root@centos test]# zip test02.zip test02 adding: test02 (deflated 85%) [root@centos test]# ll total 244 -rw-r--r--. 1 root root 193746 Sep 23 13:24 test02 -rw-r--r--. 1 root root 19565 Sep 23 13:24 test02.bz2 -rw-r--r--. 1 root root 29515 Sep 23 13:32 test02.zip压缩目录, 需要指定所有文件
[root@centos tmp]# zip test.zip test/* adding: test/test02 (deflated 85%) adding: test/test02.bz2 (deflated 3%) adding: test/test02.zip (stored 0%)解压缩: unzip 压缩文档.zip, 只能解压到当前目录
[root@centos test02]# unzip test.zip Archive: test.zip inflating: test/test02 inflating: test/test02.bz2 extracting: test/test02.zip [root@centos test02]# ll test/ total 244 -rw-r--r--. 1 root root 193746 Sep 23 13:24 test02 -rw-r--r--. 1 root root 19565 Sep 23 13:24 test02.bz2 -rw-r--r--. 1 root root 29515 Sep 23 13:32 test02.zip
归档
创建归档
格式: tar cf 归档文件.tar 要归档的所有文件夹或文件
不用像zip,指定目录内所有文件
[root@centos test02]# tar -cf testtar.tar test/ dir/
展开归档, 到当前目录, 不会删除压缩文件
tar xf tar文件
[root@centos test02]# tar -xf testtar.tar
查看归档内文件
tar -tf tar文件
[root@centos test02]# tar -tf testtar.tar test/ test/test02.zip test/test02 test/test02.bz2 dir/
归档后压缩调用
压缩并归档
格式:tar -zcf 文件.tar.gz 文件
-z可替换其他压缩格式, 后缀也要有相应修改
-z: gzip, -j: bzip2, -J: xz
[root@centos test02]# tar -zcf test.tar.gz test/ [root@centos test02]# ll test.tar.gz -rw-r--r--. 1 root root 78836 Sep 23 13:54 test.tar.gz解压归档并压缩过的文件, 不用关心是那种格式压缩的
t格式 ar xf 压缩并归档后的文件
[root@centos test02]# tar -xf test.tar.gz
相关文章推荐
- 【学习笔记】系列三:Linux安装APR
- 【学习笔记】系列四:Linux安装PCRE
- Linux 定时任务 crontab
- Linux服务器--2.DNS服务器的主从配置
- 清理linux swap内存,需要root权限
- 红帽Redhat6.4 iso下载地址
- CentOS 5.5安装gcc
- CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡
- linux安装rpm包时遇到Failed dependencies的解决办法
- Linux 进程空间,内存四区里都是些什么东西
- mysql linux安装
- linux常用的makefile模版编写-转
- Linux中使用expect脚本实现远程机器自动登录
- centos 挂载磁盘
- linux:SUID、SGID详解
- Linux SVN 命令大全
- linux下32位汇编hello, world!
- Media---I,P,B帧区别
- Linux各个服务的配置命令
- linux运维实战练习-2015年9月13日-9月15日课程作业