Linux打包与压缩命令
注:前面的zip命令是借鉴蒲公英的文章http://www.pgygho.com/help/fwq/10122.html,后面的gzip和tar是个人加的
所谓压缩就是将原有的文件通过不同的编码技术进行运算,以减少数据存储所需要的空间,使用前再利用解压缩还原源文件的内容即可。
和windows一样,在linux下也存在多种压缩与解压缩方法。
1、zip压缩与解压缩
zip是最为广泛使用的压缩程序,经它压缩的文件会产生扩展名为zip的压缩文件,而且这种格式在多种系统上可以使用,像windows中的winzip
下面看一下在linux中如何建立zip文件。
我们在终端中输入zip会出现这个命令的一些介绍和参数的意义。
代码如下:
xiaopeng@ubuntu:~/test$ zip
Copyright (c) 1990-2006 Info-ZIP - Type 'zip "-L"' for software license.
Zip 2.32 (June 19th 2006). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
-f freshen: only changed files -u update: only changed or new files
-d delete entries in zipfile -m move into zipfile (delete files)
-r recurse into directories -j junk (don't record) directory names
-0 store only -l convert LF to CR LF (-ll CR LF to LF)
-1 compress faster -9 compress better
-q quiet operation -v verbose operation/print version info
-c add one-line comments -z add zipfile comment
-@ read names from stdin -o make zipfile as old as latest entry
-x exclude the following names -i include only the following names
-F fix zipfile (-FF try harder) -D do not add directory entries
-A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)
-T test zipfile integrity -X eXclude eXtra file attributes
-y store symbolic links as the link instead of the referenced file
-R PKZIP recursion (see manual)
-e encrypt -n don't compress these suffixes
下面我们就最简单的实验一下。我们就是把当前目录下文件名以test开头的所有文件压缩文一个文件,并可以查看一下压缩比。(红色是我的注释)
代码如下:
xiaopeng@ubuntu:~/test$ ls -lh
总用量 24K
代码如下:
-rw-r--r-- 1 xiaopeng xiaopeng 212 2009-06-25 14:13 test1
-rw-r--r-- 1 xiaopeng xiaopeng 1.3K 2009-06-25 14:13 test2
-rw-r--r-- 1 xiaopeng xiaopeng 3.4K 2009-06-25 14:14 test3
-rw-r--r-- 1 xiaopeng xiaopeng 9.9K 2009-06-25 14:14 test4
代码如下:
xiaopeng@ubuntu:~/test$ zip test.zip test*
zip命令后面先跟压缩后的文件名,这里是test.zip,当然后缀名不是必须的。然后跟要压缩的文件名。这里用的test*指的是全部以test开头的文件,包括test1 test2 test3 test4
adding: test1 (deflated 30%) 这里显示的是压缩比
adding: test2 (deflated 65%)
adding: test3 (deflated 64%)
adding: test4 (deflated 73%) 大体可以看出源文件越大,压缩比就越大
代码如下:
xiaopeng@ubuntu:~/test$ ls -lh
总用量 32K
代码如下:
-rw-r--r-- 1 xiaopeng xiaopeng 212 2009-06-25 14:13 test1
-rw-r--r-- 1 xiaopeng xiaopeng 1.3K 2009-06-25 14:13 test2
-rw-r--r-- 1 xiaopeng xiaopeng 3.4K 2009-06-25 14:14 test3
-rw-r--r-- 1 xiaopeng xiaopeng 9.9K 2009-06-25 14:14 test4
-rw-r--r-- 1 xiaopeng xiaopeng 5.0K 2009-06-25 14:17 test.zip
xiaopeng@ubuntu:~/test$
上面是压缩了相同类型的文件,其实也可以把不同类型的文件压缩到一起。有时候为了节省硬盘空间,可以在建立压缩文件后,自动删除原始文件,此时只要带一个 -m 的参数就可以。
代码如下:
xiaopeng@ubuntu:~/test$ ls -lh
总用量 24K
代码如下:
-rw-r--r-- 1 xiaopeng xiaopeng 212 2009-06-25 14:13 test1
-rw-r--r-- 1 xiaopeng xiaopeng 1.3K 2009-06-25 14:13 test2
-rw-r--r-- 1 xiaopeng xiaopeng 3.4K 2009-06-25 14:14 test3
-rw-r--r-- 1 xiaopeng xiaopeng 9.9K 2009-06-25 14:14 test4
xiaopeng@ubuntu:~/test$ zip -m test.zip test* 带参数-m
updating: test1 (deflated 30%)
updating: test2 (deflated 65%)
updating: test3 (deflated 64%)
updating: test4 (deflated 73%)
xiaopeng@ubuntu:~/test$ ls -lh
总用量 8.0K
代码如下:
-rw-r--r-- 1 xiaopeng xiaopeng 5.0K 2009-06-25 14:26 test.zip
xiaopeng@ubuntu:~/test$
可以看出 原始文件已经被删除,只有压缩文件留下了。
在压缩一些目录的时候,经出在目录中会有子目录,此时根据子目录中的文件是否压缩分为两种情况,一种是压缩,一种是忽略自录中的内容,如果选择压缩子目录,则使用-r参数,如果不压缩,则使用-j 参数
下面举例,一个是-r 一个是-j
代码如下:
xiaopeng@ubuntu:~/test$ ls -lh
总用量 28K
代码如下:
drwxr-xr-x 2 xiaopeng xiaopeng 4.0K 2009-06-25 14:31 pdf
-rw-r--r-- 1 xiaopeng xiaopeng 212 2009-06-25 14:13 test1
-rw-r--r-- 1 xiaopeng xiaopeng 1.3K 2009-06-25 14:13 test2
-rw-r--r-- 1 xiaopeng xiaopeng 3.4K 2009-06-25 14:14 test3
-rw-r--r-- 1 xiaopeng xiaopeng 9.9K 2009-06-25 14:14 test4
xiaopeng@ubuntu:~/test$ zip -r test.zip * 压缩当前目录所有内容,r 参数说明pdf这个子目录中的内容也压缩
adding: pdf/ (stored 0%)
adding: pdf/case_Contact.pdf (deflated 10%)
adding: pdf/case_KRUU.pdf (deflated 9%)
adding: pdf/case_howard_county_library.pdf (deflated 24%)
adding: test1 (deflated 30%)
adding: test2 (deflated 65%)
adding: test3 (deflated 64%)
adding: test4 (deflated 73%)
xiaopeng@ubuntu:~/test$
下面的情况是子目录不压缩
代码如下:
xiaopeng@ubuntu:~/test$ ls -l
总用量 28
代码如下:
drwxr-xr-x 2 xiaopeng xiaopeng 4096 2009-06-25 14:31 pdf
-rw-r--r-- 1 xiaopeng xiaopeng 212 2009-06-25 14:13 test1
-rw-r--r-- 1 xiaopeng xiaopeng 1233 2009-06-25 14:13 test2
-rw-r--r-- 1 xiaopeng xiaopeng 3412 2009-06-25 14:14 test3
-rw-r--r-- 1 xiaopeng xiaopeng 10091 2009-06-25 14:14 test4
xiaopeng@ubuntu:~/test$ zip -j test.zip *
adding: test1 (deflated 30%)
adding: test2 (deflated 65%)
adding: test3 (deflated 64%)
adding: test4 (deflated 73%)
子目录pdf被忽略
代码如下:
xiaopeng@ubuntu:~/test$
2.gzip命令(压缩后源文件会消失)
gzip f1 #压缩文件f1
gzip -d f1.gz #解压文件f1.gz,等同于 gunzip f1.gz
gzip -1 ~ 9 f1 #按照指定级别压缩,数字越大,压缩比例越大 (这里是数字1至9)
gzip -l f1.gz #查看压缩比例
3.tar命令(打包命令,用于压缩时需要配合gzip命令)
tar -czvf x.tar.gz f1 f2 #将f1和f2压缩为x.tar.gz (注:x.tar.gz等同于x.tgz)
tar -xzvf x.tar.gz #将x.tar.gz解压缩
tar -xzvf x.tar.gz -C /root #将x.tar.gz解压缩到指定目录,这里是解压缩到/root目录下
tar -tzvf x.tar.gz #查看压缩包中的内容
Linux打包与压缩命令相关推荐
- Linux 打包及压缩命令使用方法总结
欢迎关注方志朋的博客,回复"666"获面试宝典 来源:https://tanjuntao.github.io/ 1. 概览 在这篇文章中,我将总结 Linux 系统下面常见的几种压 ...
- Linux.打包和压缩命令
这里之所以把压缩和打包的命令放在一块,原因是表象上,这两个命令类似. 打包:只是将很多个文件放在一个文件中.把棉花装在一个袋子中. 压缩:打包后,对文件进行压缩.把棉花装在一个袋子中,并用绳子捆住减少 ...
- linux tar zcxf,tar/gzip/zip文件打包、压缩命令
一.tar打包备份工具 1.命令功能 tar 将多个文件或目录打包在一起,可用通过调用gzip或zip实现压缩.解压的命令:tar不仅可以多多个文件进行打包,还可以对多个文件打包后进行压缩. 2.语法 ...
- Linux中的压缩命令
Linux中的压缩命令 1.常用压缩格式: a) .zip b) .gz c) .bz2 d) .tar.gz e) .tar.bz2 2 ...
- Linux系统常见压缩命令
Linux 系统常见的压缩命令 记录. 环境:CentOS 8 Linux的扩展名没有什么特别的作用,但在Linux环境中,压缩文件的扩展名大多是 *.tar,*.tar.gz,*.tgz,*.gz, ...
- linux压缩命令bzip2,Linux上常用压缩命令gzip,bzip2,zip/unzip
Linux上常用压缩命令gzip,bzip2,zip/unzip 1. gzip gzip生成的压缩文件为*.gz 格式: gzip [-cdtv#] file 主要参数: -c :将压缩的数据输出到 ...
- linux打包文件夹命令
原文链接:linux打包文件夹命令 linux打包文件夹命令如下 .tar文件 例:文件夹名为fileName 打包:tar cvf fileName.tar logs/ 解压:tar xvf fil ...
- linux下的打包和解压缩命令,浅析Linux打包压缩解压缩命令大全(收藏)
下面是小编日常收集整理的关于linux打包压缩解压缩命令大全,具体内容如下所述: tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar Dir ...
- tar/gzip/zip文件打包、压缩命令
一.tar打包备份工具 1.命令功能 tar 将多个文件或目录打包在一起,可用通过调用gzip或zip实现压缩.解压的命令:tar不仅可以多多个文件进行打包,还可以对多个文件打包后进行压缩. 2.语法 ...
- Linux 打包和压缩
常用的打包压缩方式 windows常用rar mac常用zip linux常用tar.gz 打包/解包 tar是linux中最常用的备份工具,此命令可以把一系列的文件打包到一个大文件中,也可以把一个打 ...
最新文章
- intent传递有没有大小限制,是多少?
- 微信小程序wxparse内容页显示不出来不能正确解析html代码
- iOS 仿通讯录索引
- c# 学习笔记 (3) 窗体单例模式
- 开启mapper接口扫描,添加分页插件
- Strange Birthday Party CodeForces - 1471C
- python3.8安装教程 20200701
- 软考路:高项4流水账
- react native 学习
- c++11 线程的互斥量
- tag untag_交换机该怎么理解Hybird中Tag和Untag端口模式?
- Mcafee杀毒软件卸载不了
- 视频教程-JQuery全套视频-jQuery
- 08.第三章 数字特征与特征函数(1)
- 穿孔发光字/外露发光字制作流程步骤
- 多商户JAVA扫码点餐小程序源码SaaS模式
- 写给大家看的CSS书,写给大家看的设计书
- PHP项目集成支付宝PC端扫码支付API(国内支付)
- iOS8的三种分辨率
- magento怎么修改货币符号,在之前加上国家缩写