每天一个Linux命令(27)gzip命令
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了每天一个Linux命令(27)gzip命令,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6006字,纯文字阅读大概需要9分钟。
内容图文
![每天一个Linux命令(27)gzip命令](/upload/InfoBanner/zyjiaocheng/1319/2e454767c8f04946a1e3882b63f3b8a6.jpg)
zip命令用来压缩文件。gzip是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多处“.gz”扩展名。
(1)用法:
用法: gzip [选项参数][-s <压缩字尾字符串>] [文件...]
或 gzip [选项参数][-s <压缩字尾字符串>] [目录]
(2)功能:
功能: gzip是个使用广泛的解压缩程序,它用于解开被gzip压缩过的文件,这些压缩文件预设最后的扩展名为".gz"。
事实上gzip就是gzip的硬连接,因此不论是压缩或解压缩,都可通过gzip指令单独完成。
(3)选项参数:
1) -d --decompress --uncompress 解开压缩文件;
2) -v --verbose 显示指令执行过程;
3) -l --list 列出压缩文件的相关信息;
4) -r --recursive 递归处理,将指定目录下的所有文件及子目录一并处理;
5) -A --catenate: 新增文件到已存在的备份文件;
6) -B 设置区块大小
7) -c 把解压后的文件输出到标准输出设备
(4)实例:
1)[root@localhost Dir]# gzip * 压缩当前目录下的所有文件,文件后缀名加上.gz(gzip调用时自动执行压缩或解压缩命令)
[root@localhost Dir]# gzip * [root@localhost Dir]# ll 总用量 12 -r-xr-xr-x. 1 sunjimeng root 411 5月 907:59 head_text.gz -r-xr-xr-x. 1 root sunjimeng 67 5月 908:15 less1.gz -r-xr-xr-x. 1 root sunjimeng 80 5月 908:16 less2.gz
2)[root@localhost Dir]# gzip -d * 解压当前目录的所有文件
[root@localhost Dir]# gzip * //解压并不能像压缩时那样什么参数都不带,需要带解压命令-d gzip: head_text.gz already has .gz suffix -- unchanged gzip: less1.gz already has .gz suffix -- unchanged gzip: less2.gz already has .gz suffix -- unchanged [root@localhost Dir]# gzip -d * [root@localhost Dir]# ll 总用量 12 -r-xr-xr-x. 1 sunjimeng root 664 5月 907:59 head_text -r-xr-xr-x. 1 root sunjimeng 45 5月 908:15 less1 -r-xr-xr-x. 1 root sunjimeng 57 5月 908:16 less2
3)[root@localhost Dir]# gzip -v * 显示命令执行时的具体的步骤
[root@localhost Dir]# gzip -v * head_text: 42.3% -- replaced with head_text.gz less1: 4.4% -- replaced with less1.gz less2: 1.8% -- replaced with less2.gz [root@localhost Dir]# gzip -dv * head_text.gz: 42.3% -- replaced with head_text less1.gz: 4.4% -- replaced with less1 less2.gz: 1.8% -- replaced with less2
4)[root@localhost Dir]# gzip -l *
[root@localhost Dir]# gzip -l * compressed uncompressed ratio uncompressed_name 41166442.3% head_text 67454.4% less1 80571.8% less2 55876630.3% (totals) [root@localhost Dir]# ll 总用量 12 -r-xr-xr-x. 1 sunjimeng root 411 5月 907:59 head_text.gz -r-xr-xr-x. 1 root sunjimeng 67 5月 908:15 less1.gz -r-xr-xr-x. 1 root sunjimeng 80 5月 908:16 less2.gz
5)[root@localhost findDir]# tar -cvf Dir.tar Dir 先用tar命令打包
[root@localhost findDir]# tar -cvf Dir.tar Dir Dir/ Dir/head_text.gz Dir/less1.gz Dir/less2.gz [root@localhost findDir]# ll 总用量 12 dr-xr-xr-x. 2 root sunjimeng 55 5月 2407:28 Dir -rw-r--r--. 1 root root 10240 5月 2407:34 Dir.tar [root@localhost findDir]# gzip -v Dir.tar Dir.tar: 92.1% -- replaced with Dir.tar.gz [root@localhost findDir]# gzip -l Dir.tar.gz compressed uncompressed ratio uncompressed_name 8331024092.1% Dir.tar
5)[root@localhost findDir]# tar cvf Dir1.tar -R Dir 打包的几种方法
[root@localhost findDir]# tar cvf Dir1.tar -R Dir 块 0:Dir/ 块 1:Dir/head_text.gz 块 3:Dir/less1.gz 块 5:Dir/less2.gz [root@localhost findDir]# tar -cvf Dir2.tar Dir Dir/ Dir/head_text.gz Dir/less1.gz Dir/less2.gz [root@localhost findDir]# tar -cvf Dir3.tar -R Dir 块 0:Dir/ 块 1:Dir/head_text.gz 块 3:Dir/less1.gz 块 5:Dir/less2.gz
6)[root@localhost Documents]# gzip -vr findDir 递归的压缩子文件夹下的文件
[root@localhost Documents]# gzip -vr findDir gzip: findDir/Dir/head_text.gz already has .gz suffix -- unchanged gzip: findDir/Dir/less1.gz already has .gz suffix -- unchanged gzip: findDir/Dir/less2.gz already has .gz suffix -- unchanged gzip: findDir/Dir.tar.gz already has .gz suffix -- unchanged findDir/Dir1.tar: 92.1% -- replaced with findDir/Dir1.tar.gz findDir/Dir2.tar: 92.1% -- replaced with findDir/Dir2.tar.gz findDir/Dir3.tar: 92.1% -- replaced with findDir/Dir3.tar.gz [root@localhost Documents]# ls -l findDir 总用量 16 -rw-r--r--. 1 root root 833 5月 2407:34 Dir.tar.gz -rw-r--r--. 1 root root 834 5月 2407:43 Dir3.tar.gz -rw-r--r--. 1 root root 834 5月 2407:39 Dir2.tar.gz -rw-r--r--. 1 root root 834 5月 2407:39 Dir1.tar.gz dr-xr-xr-x. 2 root sunjimeng 55 5月 2407:28 Dir [root@localhost Documents]# ls -l findDir/Dir 总用量 12 -r-xr-xr-x. 1 root sunjimeng 80 5月 908:16 less2.gz -r-xr-xr-x. 1 root sunjimeng 67 5月 908:15 less1.gz -r-xr-xr-x. 1 sunjimeng root 411 5月 907:59 head_text.gz
7)[root@localhost findDir]# gzip -rdv Dir 递归的解压目录下的所有.gz的文件
[root@localhost findDir]# ls -l Dir 总用量 12 -r-xr-xr-x. 1 sunjimeng root 411 5月 907:59 head_text.gz -r-xr-xr-x. 1 root sunjimeng 67 5月 908:15 less1.gz -r-xr-xr-x. 1 root sunjimeng 80 5月 908:16 less2.gz [root@localhost findDir]# gzip -rdv Dir Dir/head_text.gz: 42.3% -- replaced with Dir/head_text Dir/less1.gz: 4.4% -- replaced with Dir/less1 Dir/less2.gz: 1.8% -- replaced with Dir/less2 [root@localhost findDir]# ls -l Dir 总用量 12 -r-xr-xr-x. 1 sunjimeng root 664 5月 907:59 head_text -r-xr-xr-x. 1 root sunjimeng 45 5月 908:15 less1 -r-xr-xr-x. 1 root sunjimeng 57 5月 908:16 less2 [root@localhost findDir]# gzip -r Dir [root@localhost findDir]# ls -l Dir 总用量 12 -r-xr-xr-x. 1 sunjimeng root 411 5月 907:59 head_text.gz -r-xr-xr-x. 1 root sunjimeng 67 5月 908:15 less1.gz -r-xr-xr-x. 1 root sunjimeng 80 5月 908:16 less2.gz [root@localhost findDir]# gzip -dv Dir gzip: Dir is a directory -- ignored
8)[root@localhost Dir]# gzip --help
[root@localhost Dir]# gzip --help Usage: gzip [OPTION]... [FILE]... Compress or uncompress FILEs (by default, compress FILES in-place). Mandatory arguments to long options are mandatory forshort options too. -c, --stdout write on standard output, keep original files unchanged -d, --decompress decompress -f, --force force overwrite of output file and compress links -h, --help give this help -l, --list list compressed file contents -L, --license display software license -n, --no-name do not save or restore the original name and time stamp -N, --name save or restore the original name and time stamp -q, --quiet suppress all warnings -r, --recursive operate recursively on directories -S, --suffix=SUF use suffix SUF on compressed files -t, --test test compressed file integrity -v, --verbose verbose mode -V, --version display version number -1, --fast compress faster -9, --best compress better --rsyncable Make rsync-friendly archive With no FILE, or when FILE is -, read standard input. Report bugs to <bug-gzip@gnu.org>.
原文:http://www.cnblogs.com/MenAngel/p/5525362.html
内容总结
以上是互联网集市为您收集整理的每天一个Linux命令(27)gzip命令全部内容,希望文章能够帮你解决每天一个Linux命令(27)gzip命令所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。