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)[[email protected] Dir]# gzip * 压缩当前目录下的所有文件,文件后缀名加上.gz(gzip调用时自动执行压缩或解压缩命令)
[[email protected] Dir]# gzip *12
-r-xr-xr-x. 1 sunjimeng root 411 5月 9 07:59head_text.gz-r-xr-xr-x. 1 root sunjimeng 67 5月 9 08:15less1.gz-r-xr-xr-x. 1 root sunjimeng 80 5月 9 08:16less2.gz
2)[[email protected] Dir]# gzip -d * 解压当前目录的所有文件
[[email protected] Dir]# gzip * //解压并不能像压缩时那样什么参数都不带,需要带解压命令-dgzip: head_text.gz already has .gz suffix--unchanged
gzip: less1.gz already has .gz suffix--unchanged
gzip: less2.gz already has .gz suffix--unchanged
[[email protected] Dir]# gzip-d *12
-r-xr-xr-x. 1 sunjimeng root 664 5月 9 07:59head_text-r-xr-xr-x. 1 root sunjimeng 45 5月 9 08:15less1-r-xr-xr-x. 1 root sunjimeng 57 5月 9 08:16 less2
3)[[email protected] Dir]# gzip -v * 显示命令执行时的具体的步骤
[[email protected] 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
[[email protected] 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)[[email protected] Dir]# gzip -l *
[[email protected] Dir]# gzip -l *compressed uncompressed ratio uncompressed_name411 664 42.3%head_text67 45 4.4%less180 57 1.8%less2558 766 30.3%(totals)
[[email protected] Dir]# ll
总用量12
-r-xr-xr-x. 1 sunjimeng root 411 5月 9 07:59head_text.gz-r-xr-xr-x. 1 root sunjimeng 67 5月 9 08:15less1.gz-r-xr-xr-x. 1 root sunjimeng 80 5月 9 08:16 less2.gz
5)[[email protected] findDir]# tar -cvf Dir.tar Dir 先用tar命令打包
[[email protected] findDir]# tar -cvf Dir.tar Dir
Dir/Dir/head_text.gz
Dir/less1.gz
Dir/less2.gz
[[email protected] findDir]# ll
总用量12dr-xr-xr-x. 2 root sunjimeng 55 5月 24 07:28Dir-rw-r--r--. 1 root root 10240 5月 24 07:34Dir.tar
[[email protected] findDir]# gzip-v Dir.tar
Dir.tar:92.1% --replaced with Dir.tar.gz
[[email protected] findDir]# gzip-l Dir.tar.gz
compressed uncompressed ratio uncompressed_name833 10240 92.1% Dir.tar
5)[[email protected] findDir]# tar cvf Dir1.tar -R Dir 打包的几种方法
[[email protected] findDir]# tar cvf Dir1.tar -R Dir
块0:Dir/块1:Dir/head_text.gz
块3:Dir/less1.gz
块5:Dir/less2.gz
[[email protected] findDir]# tar-cvf Dir2.tar Dir
Dir/Dir/head_text.gz
Dir/less1.gz
Dir/less2.gz
[[email protected] findDir]# tar-cvf Dir3.tar -R Dir
块0:Dir/块1:Dir/head_text.gz
块3:Dir/less1.gz
块5:Dir/less2.gz
6)[[email protected] Documents]# gzip -vr findDir 递归的压缩子文件夹下的文件
[[email protected] 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
[[email protected] Documents]# ls-l findDir
总用量16
-rw-r--r--. 1 root root 833 5月 24 07:34Dir.tar.gz-rw-r--r--. 1 root root 834 5月 24 07:43Dir3.tar.gz-rw-r--r--. 1 root root 834 5月 24 07:39Dir2.tar.gz-rw-r--r--. 1 root root 834 5月 24 07:39Dir1.tar.gz
dr-xr-xr-x. 2 root sunjimeng 55 5月 24 07:28Dir
[[email protected] Documents]# ls-l findDir/Dir
总用量12
-r-xr-xr-x. 1 root sunjimeng 80 5月 9 08:16less2.gz-r-xr-xr-x. 1 root sunjimeng 67 5月 9 08:15less1.gz-r-xr-xr-x. 1 sunjimeng root 411 5月 9 07:59 head_text.gz
7)[[email protected] findDir]# gzip -rdv Dir 递归的解压目录下的所有.gz的文件
[[email protected] findDir]# ls -l Dir
总用量12
-r-xr-xr-x. 1 sunjimeng root 411 5月 9 07:59head_text.gz-r-xr-xr-x. 1 root sunjimeng 67 5月 9 08:15less1.gz-r-xr-xr-x. 1 root sunjimeng 80 5月 9 08:16less2.gz
[[email protected] 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
[[email protected] findDir]# ls-l Dir
总用量12
-r-xr-xr-x. 1 sunjimeng root 664 5月 9 07:59head_text-r-xr-xr-x. 1 root sunjimeng 45 5月 9 08:15less1-r-xr-xr-x. 1 root sunjimeng 57 5月 9 08:16less2
[[email protected] findDir]# gzip-r Dir
[[email protected] findDir]# ls-l Dir
总用量12
-r-xr-xr-x. 1 sunjimeng root 411 5月 9 07:59head_text.gz-r-xr-xr-x. 1 root sunjimeng 67 5月 9 08:15less1.gz-r-xr-xr-x. 1 root sunjimeng 80 5月 9 08:16less2.gz
[[email protected] findDir]# gzip-dv Dir
gzip: Diris a directory -- ignored
8)[[email protected]lhost Dir]# gzip --help
[[email protected] Dir]# gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (bydefault, compress FILES in-place).
Mandatory arguments tolong options are mandatory for shortoptions 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 thishelp-l, --list list compressed file contents-L, --license display software license-n, --no-name donot 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 FILEis -, read standard input.
Report bugs to.