壓縮 與解壓縮

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.logide

#[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.Zcode

[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.logip

[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.jpgit

[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]$io

[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)? ast

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.jpgclass

[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 2020sed

[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

相關文章
相關標籤/搜索