Linux 命令(文件和目录管理 - gzip/gunzip)
来源:互联网 发布:手机棋牌游戏源码 编辑:程序博客网 时间:2024/05/18 09:18
简述
和 zip 命令类似,gzip 用于文件的压缩,gzip 压缩后的文件扩展名位 .gz,gzip 默认压缩后会删除原文件。gunzip 用于解压经过 gzip 压缩过的文件。
- 简述
- gzip
- 命令介绍
- 命令选项
- 使用范例
- gunzip
- 命令介绍
- 命令选项
- 使用范例
gzip
命令介绍
命令名称
gzip基本语法
gzip [OPTION]… [FILE]…功能描述
压缩文件。压缩后的文件扩展名位 .gz,默认压缩后会删除原文件。
命令选项
-a --ascii
使用 ASCII 文字模式 -c, --stdout
把压缩后的文件输出到标准输出设备,保持原始文件不变。 -d, --decompress
对压缩的文件进行解压 -f, --force
强行压缩文件,不理会文件名称或硬连接是否存在以及该文件是否为符号连接。 -h, --help
在线帮助 -l, --list
列出压缩文件的相关信息 -L, --license
显示 license -n, --no-name
压缩文件时,不保存或恢复原来的名字和时间戳 -N, --name
压缩文件时,保存或恢复原来的名字和时间戳 -q, --quiet
不显示警告信息 -r, --recursive
递归压缩指定目录以及子目录下的所有文件 -S, --suffix=SU
更改压缩文件字尾字符串为 SUF -t, --test
检查压缩文档的完整性 -v, --verbose
显示指令执行过程 -V, --version
显示版本信息 -# --fast --best
用指定的数字 # 调整压缩速度,-1 或 --fast
表示最快压缩方法(低压缩比),-9 或 --best
表示最慢压缩方法(高压缩比)。系统缺省值为6(偏高压缩比)。使用范例
1.压缩文件,压缩后原文件被删除
[wang@localhost linux]$ ls -l总用量 33132-rw-rw-r--. 1 wang wang 31 9月 29 11:03 hello.sh-rw-r--r--. 1 wang wang 33921784 6月 7 11:02 linux-program.pdf# 压缩文件 hello.sh,压缩后的文件为 hello.sh.gz[wang@localhost linux]$ gzip hello.sh [wang@localhost linux]$ ls -l总用量 33132-rw-rw-r--. 1 wang wang 60 9月 29 11:03 hello.sh.gz-rw-r--r--. 1 wang wang 33921784 6月 7 11:02 linux-program.pdf# gzip 压缩过的文件的特性[wang@localhost linux]$ file hello.sh.gz hello.sh.gz: gzip compressed data, was "hello.sh", from Unix, last modified: Thu Sep 29 11:03:24 2016
2.压缩后,保留原文件
# 计算压缩后文件的 md5 值[wang@localhost linux]$ gzip hello.sh [wang@localhost linux]$ md5sum hello.sh.gz edf22795963c6264df42970855a14efe hello.sh.gz# 解压缩(还原回去)[wang@localhost linux]$ gunzip hello.sh.gz# 如果要保留原文件,使用下面命令[wang@localhost linux]$ gzip -c hello.sh >hello.sh.gz[wang@localhost linux]$ lshello.sh hello.sh.gz linux-program.pdf[wang@localhost linux]$ md5sum hello.sh.gz edf22795963c6264df42970855a14efe hello.sh.gz
显然,校验 md5 值,和直接使用 gzip 一致。
3.压缩时,显示指令执行过程
[wang@localhost linux]$ gzip -v hello.sh hello.sh: -6.5% -- replaced with hello.sh.gz[wang@localhost linux]$ ls -l总用量 33132-rw-rw-r--. 1 wang wang 60 9月 29 11:03 hello.sh.gz-rw-r--r--. 1 wang wang 33921784 6月 7 11:02 linux-program.pdf
4.将目录 c 下的每个文件压缩成 .gz 文件
[wang@localhost c]$ ls -l总用量 16976-rw-rw-r--. 1 wang wang 60 9月 29 11:05 hello.c-rw-r--r--. 1 wang wang 7283461 12月 14 2015 QmlBook-In-Chinese.pdf-rw-r--r--. 1 wang wang 7484327 12月 16 2015 qt5_cadaques.pdf-rw-r--r--. 1 wang wang 2604948 1月 18 2016 qwt-6.1.1.pdf[wang@localhost c]$ gzip *[wang@localhost c]$ ls -l总用量 15052-rw-rw-r--. 1 wang wang 86 9月 29 11:05 hello.c.gz-rw-r--r--. 1 wang wang 5778415 12月 14 2015 QmlBook-In-Chinese.pdf.gz-rw-r--r--. 1 wang wang 7157026 12月 16 2015 qt5_cadaques.pdf.gz-rw-r--r--. 1 wang wang 2466302 1月 18 2016 qwt-6.1.1.pdf.gz
注意:如果是目录,将被忽略。
5.将每个被压缩的文件解压
[wang@localhost c]$ ls -l总用量 15052-rw-rw-r--. 1 wang wang 86 9月 29 11:05 hello.c.gz-rw-r--r--. 1 wang wang 5778415 12月 14 2015 QmlBook-In-Chinese.pdf.gz-rw-r--r--. 1 wang wang 7157026 12月 16 2015 qt5_cadaques.pdf.gz-rw-r--r--. 1 wang wang 2466302 1月 18 2016 qwt-6.1.1.pdf.gz[wang@localhost c]$ gzip -d *[wang@localhost c]$ ls -l总用量 16976-rw-rw-r--. 1 wang wang 60 9月 29 11:05 hello.c-rw-r--r--. 1 wang wang 7283461 12月 14 2015 QmlBook-In-Chinese.pdf-rw-r--r--. 1 wang wang 7484327 12月 16 2015 qt5_cadaques.pdf-rw-r--r--. 1 wang wang 2604948 1月 18 2016 qwt-6.1.1.pdf
6.详细显压缩文件的信息(不解压)
[wang@localhost c]$ gzip -l * compressed uncompressed ratio uncompressed_name 86 60 0.0% hello.c 5778415 7283461 20.7% QmlBook-In-Chinese.pdf 7157026 7484327 4.4% qt5_cadaques.pdf 2466302 2604948 5.3% qwt-6.1.1.pdf 15401829 17372796 11.3% (totals)
7.递归的压缩目录
使用 -r 选项,递归压缩 doc 目录以及子目录下的所有文件(目录依然存在)。
# 压缩前的目录树[wang@localhost ~]$ tree docdoc├── c│ ├── hello.c│ ├── QmlBook-In-Chinese.pdf│ ├── qt5_cadaques.pdf│ └── qwt-6.1.1.pdf├── css├── debug.log├── js├── linux│ ├── hello.sh│ └── linux-program.pdf└── program4 directories, 8 files# 递归压缩 doc 目录[wang@localhost ~]$ gzip -rv docdoc/linux/linux-program.pdf: 2.1% -- replaced with doc/linux/linux-program.pdf.gzdoc/linux/hello.sh: -6.5% -- replaced with doc/linux/hello.sh.gzdoc/c/hello.c: 0.0% -- replaced with doc/c/hello.c.gzdoc/c/QmlBook-In-Chinese.pdf: 20.7% -- replaced with doc/c/QmlBook-In-Chinese.pdf.gzdoc/c/qt5_cadaques.pdf: 4.4% -- replaced with doc/c/qt5_cadaques.pdf.gzdoc/c/qwt-6.1.1.pdf: 5.3% -- replaced with doc/c/qwt-6.1.1.pdf.gzdoc/debug.log: 97.8% -- replaced with doc/debug.log.gzdoc/program: 0.0% -- replaced with doc/program.gz# 压缩后的目录树[wang@localhost ~]$ tree docdoc├── c│ ├── hello.c.gz│ ├── QmlBook-In-Chinese.pdf.gz│ ├── qt5_cadaques.pdf.gz│ └── qwt-6.1.1.pdf.gz├── css├── debug.log.gz├── js├── linux│ ├── hello.sh.gz│ └── linux-program.pdf.gz└── program.gz4 directories, 8 files
8.递归的解压目录
# 解压前的目录树[wang@localhost ~]$ tree docdoc├── c│ ├── hello.c.gz│ ├── QmlBook-In-Chinese.pdf.gz│ ├── qt5_cadaques.pdf.gz│ └── qwt-6.1.1.pdf.gz├── css├── debug.log.gz├── js├── linux│ ├── hello.sh.gz│ └── linux-program.pdf.gz└── program.gz4 directories, 8 files# 递归解压 doc 目录[wang@localhost ~]$ gzip -dr doc# 解压后的目录树[wang@localhost ~]$ tree docdoc├── c│ ├── hello.c│ ├── QmlBook-In-Chinese.pdf│ ├── qt5_cadaques.pdf│ └── qwt-6.1.1.pdf├── css├── debug.log├── js├── linux│ ├── hello.sh│ └── linux-program.pdf└── program4 directories, 8 files
gunzip
命令介绍
命令名称
gunzip基本语法
gunzip [OPTION]… [FILE]…功能描述
解压缩文件
命令选项
-a --ascii
使用 ASCII 文字模式 -c, --stdout
把压缩后的文件输出到标准输出设备,保持原始文件不变。 -f, --force
强行解压缩文件,不理会文件名称或硬连接是否存在以及该文件是否为符号连接。 -l, --list
列出压缩文件的相关信息 -n, --no-name
解压缩文件时,不保存或恢复原来的名字和时间戳 -N, --name
解压缩文件时,保存或恢复原来的名字和时间戳 -q, --quiet
不显示警告信息 -r, --recursive
递归解压缩指定目录以及子目录下的所有文件 -S, --suffix=SU
更改压缩文件字尾字符串为 SUF -t, --test
检查压缩文档的完整性 -v, --verbose
显示指令执行过程 --help
显示帮助信息并退出 --version
显示版本信息并退出使用范例
1.解压缩文件
[wang@localhost linux]$ lshello.sh.gz linux-program.pdf[wang@localhost linux]$ gunzip hello.sh.gz [wang@localhost linux]$ lshello.sh linux-program.pdf
2.详细显示压缩文件的信息(不解压)
[wang@localhost linux]$ gunzip -l hello.sh.gz compressed uncompressed ratio uncompressed_name 60 31 -6.5% hello.sh
3.解压缩时,显示指令执行过程
[wang@localhost linux]$ gunzip -v hello.sh.gz hello.sh.gz: -6.5% -- replaced with hello.sh[wang@localhost linux]$ lshello.sh linux-program.pdf
4.gzip –d
等价于 gunzip
# 原文件[wang@localhost linux]$ lshello.sh linux-program.pdf[wang@localhost linux]$ md5sum hello.sh 97a6ab3ff888b1ff6519df2387983aa5 hello.sh# gzip 压缩后,根据 gzip -d 解压缩[wang@localhost linux]$ gzip hello.sh [wang@localhost linux]$ lshello.sh.gz linux-program.pdf[wang@localhost linux]$ gzip -d hello.sh.gz [wang@localhost linux]$ lshello.sh linux-program.pdf[wang@localhost linux]$ md5sum hello.sh 97a6ab3ff888b1ff6519df2387983aa5 hello.sh# gzip 压缩后,根据 gunzip 解压缩[wang@localhost linux]$ gzip hello.sh [wang@localhost linux]$ lshello.sh.gz linux-program.pdf[wang@localhost linux]$ gunzip hello.sh.gz [wang@localhost linux]$ lshello.sh linux-program.pdf[wang@localhost linux]$ md5sum hello.sh 97a6ab3ff888b1ff6519df2387983aa5 hello.sh
显然,校验 md5 值,原文件与 gunzip 和使用 gzip –d
解压缩后的 md5 值一致。
通过上面的几个示例,可以看出 gzip –d
等价于 gunzip 命令。
0 0
- Linux 命令(文件和目录管理 - gzip/gunzip)
- linux gunzip/unzip gzip/zip命令用法
- gzip 和gunzip 命令简单使用说明
- gzip, gunzip ,tar命令
- linux gzip gunzip
- Linux命令之文件归档、压缩、解压缩-tar,gzip,gunzip,bzip2,bunzip2,zip
- gzip和gunzip
- tar,gunzip,gzip,unzip和zgrep 命令的区别
- tar,gunzip,gzip,unzip和zgrep 命令的区别
- gzip和gunzip 解压参数
- gzip 和 gunzip 的使用
- gzip和gunzip 解压参数
- gzip和gunzip 解压参数
- Linux文件和目录管理相关命令
- linux 文件和目录管理--基础命令
- linux管理文件和目录的命令
- Linux 命令(文件和目录管理
- Linux 命令(文件和目录管理 - pwd)
- java 循环
- leetcode 349. Intersection of Two Arrays
- 列出对像属性,for(var i in obj)
- Java中的阻塞队列
- SEO如何提升品牌优化?
- Linux 命令(文件和目录管理 - gzip/gunzip)
- Launcher长按拖拽流程
- mybatis中的#和$的区别
- 关于viewPager中设置PagerTabStrip后不显示问题
- Camera相关知识点
- Android Monkey自动化测试相关命令
- 关于 clear:both 清楚浮动
- Android通知消息总结
- Android5.0水波纹点击效果