压缩 与解压缩

1 file-roller +压缩文件图形化 打开压缩文件

# 2 [12:46:19 root@localhost dir]$ll m.log 

-rw-------. 1 root root 424638 Feb 17 12:46 m.log
[12:46:26 root@localhost dir]$ll -h m.log
-rw-------. 1 root root 415K Feb 17 12:46 m.log

#[12:46:33 root@localhost dir]$compress m.log ---compress 压缩文件后源文件消失 新文件扩展名“.Z”

[12:48:28 root@localhost dir]$ll
total 128
drwxr-xr-x. 143 root root 8192 Feb 17 12:45 etc

-rw-------. 1 root root 111769 Feb 17 12:46 m.log.Z

[12:48:30 root@localhost dir]$uncompress m.log.Z--解压缩 不适合压缩的文件 compress 不压缩

[12:55:05 root@localhost dir]$ll m.log
-rw-------. 1 root root 424638 Feb 17 12:46 m.log

[13:11:13 root@localhost dir]$ll

total 1392
drwxr-xr-x. 143 root root 8192 Feb 17 12:45 etc
-rw-r--r--. 1 root root 595 Feb 16 23:51 f1
-rw-------. 1 root root 424638 Feb 17 12:46 m.log
-rw-r--r--. 1 root root 980265 Feb 17 13:05 morning.jpg

[13:11:29 root@localhost dir]$compress -c m.log >>m.log.Z (--compress -c file 压缩输出到屏幕 重定向到文件上 源文件不消失。)

#[13:11:49 root@localhost dir]$ll m.log m.log.Z
-rw-------. 1 root root 424638 Feb 17 12:46 m.log
-rw-r--r--. 1 root root 111769 Feb 17 13:11 m.log.Z
[13:12:02 root@localhost dir]$

[13:15:50 root@localhost dir]$uncompress m.log.Z --解压缩 等价 compress -d +file.Z

m.log already exists.
Do you wish to overwrite m.log (y or n)?

zcat m.log.Z --直接打开压缩文件预览 不是解压缩

gzip m.log ---直接压缩 --不保留源文件

gzip -c m.log >>m.log.gz --保留源文件压缩

解压缩 gunzip m.log.gz --加压缩 不保留源文件

解压缩 gzip -d m.log.gz --等价gunzip m.log.gz

[14:40:09 root@localhost dir]$gzip -9 -c m.log > m2.log.gz --指定压缩比 1-9 压缩比逐渐加大

[14:41:09 root@localhost dir]$ll -h m*
-rw-r--r--. 1 root root 58K Feb 17 14:41 m2.log.gz
-rw-r--r--. 1 root root 415K Feb 17 14:31 m.log
-rw-------. 1 root root 60K Feb 17 12:46 m.log.gz
-rw-r--r--. 1 root root 110K Feb 17 13:11 m.log.Z
-rw-r--r--. 1 root root 958K Feb 17 13:05 morning.jpg

[14:53:42 root@localhost dir]$gzip -f > f3.gz --支持标准输入 重定向为f3.gz文件。

nihao
woshi zhonghua
123 ctl ^H^H^H
ctl d 结束输入
[14:57:43 root@localhost dir]$zcat f3.gz
nihao
woshi zhonghua
123 ctl
ctl d 结束输入
[14:57:51 root@localhost dir]$

[14:57:51 root@localhost dir]$file f3.gz 查看f3.gz 文件类型

f3.gz: gzip compressed data, from Unix, last modified: Mon Feb 17 14:57:03 2020

[15:08:53 root@localhost dir]$bzip2 -k m.log --bzip -k 保留源文件压缩 压缩比比gzip 高

[15:09:11 root@localhost dir]$ll -h m*
-rw-r--r--. 1 root root 58K Feb 17 14:41 m2.log.gz
-rw-r--r--. 1 root root 415K Feb 17 14:31 m.log
-rw-r--r--. 1 root root 40K Feb 17 14:31 m.log.bz2
-rw-------. 1 root root 60K Feb 17 12:46 m.log.gz
-rw-r--r--. 1 root root 110K Feb 17 13:11 m.log.Z
-rw-r--r--. 1 root root 958K Feb 17 13:05 morning.jpg

[15:28:43 root@localhost dir]$bzcat m.log.bz2 --使用 bzcat 查看bzip2 压缩的文件

[15:13:36 root@localhost dir]$ls -r /etc -l | bzip2 > list.bz2 与gzip 一样支持标准输入 重定向为压缩文件

[15:15:59 root@localhost dir]$file list.bz2
list.bz2: bzip2 compressed data, block size = 900k

压缩工具对文件后缀“suffix” 有要求 suffix不正确 无法解压缩 不识别。

bzip2 解压缩 使用 bunzip2 或 bzip2 -d 解压缩

[15:32:34 root@localhost dir]$bunzip2 list.bz2

[15:32:34 root@localhost dir]$bzip2 -d list.bz2

[15:33:05 root@localhost dir]$ll
total 1692
-rw-r--r--. 1 root root 16648 Feb 17 15:19 list

XZ /unxz/xzcat --与bzip2用法一致 也很支持管道

xz [option] ....FILE

           -k keep,保留源文件
                         -d 解压缩
                         -# 压缩比,取值 1-9 ,默认6

unxz file.xz 解压缩

xzcat file.xz 不显示解压缩的前提下查看文本文件内容

[18:37:27 root@localhost dir]$dd if=/dev/zero of=bigfile bs=1M count=1024 --创建1G大小文件

[18:41:22 root@localhost dir]$ ls -lh bigfile bigfile.gz && file bigfile.gz

-rw-r--r--. 1 root root 1.0G Feb 17 18:34 bigfile

-rw-r--r--. 1 root root 1018K Feb 17 18:36 bigfile.gz --未知的压缩文件不要轻易解压 很可能把磁盘干满。

bigfile.gz: gzip compressed data, was "bigfile", from Unix, last modified: Mon Feb 17 18:34:13 2020

猜你喜欢

转载自blog.51cto.com/12246080/2472217