6.3 bzip2壓縮工具

bzip2目錄概要

  • bzip2 1.txt 或 bzip2 -z 1.txt 壓縮文件
  • bzip2 -d 1.txt.bz2 或 bunzip2 1.txt.bz2 解壓文件
  • bzip -# 1.txt 範圍1-9,默認9
  • 不能壓縮目錄
  • bzcat 1.txt.bz2 查看壓縮文件的內容(含義爲:先解壓,後查看)
  • bzip2 -c 1.txt > /root/1.txt.gz 壓縮文件,並重定向文件的目錄和名稱
  • bzip2 -c -d /root/1.txt.bz2 > /tmp/1.txt.nws 解壓文件,並重定向文件的目錄和名稱

bzip2壓縮文件

  • 安裝bzip2包——>yum install -y bzip2
  • bzip2 1.txt 壓縮文件
[root@hf-01 d6z]# du -sh 1.txt
2.0M	1.txt
[root@hf-01 d6z]# bzip2 1.txt
[root@hf-01 d6z]# ls
1.txt.bz2
[root@hf-01 d6z]# du -sh 1.txt.bz2
168K	1.txt.bz2

bzip2解壓文件(兩種辦法)

  • bzip2 -d 1.txt 解壓文件
[root@hf-01 d6z]# bzip2 -d 1.txt.bz2
[root@hf-01 d6z]# ls
1.txt
[root@hf-01 d6z]# du -sh 1.txt
1.5M	1.txt
  • bunzip2 1.txt.bz2 解壓文件
[root@hf-01 d6z]# bunzip2 1.txt.bz2
[root@hf-01 d6z]# ls
1.txt

bzip2壓縮文件,並指定目錄

  • bzip2 -c 1.txt > /tmp/2.txt.bz2 壓縮1.txt文件,並壓縮到/tmp下2.txt.bz2
[root@hf-01 d6z]# bzip2 -c 1.txt > /tmp/2.txt.bz2
[root@hf-01 d6z]# du -sh /tmp/2.txt.bz2
168K	/tmp/2.txt.bz2

bzip解壓文件,並指定目錄(兩種方法)

  • bzip2 -d -c /tmp/2.txt.bz2 > 4.txt 解壓tmp目錄下的文件,並解壓到當前目錄下,更名爲4.txt
[root@hf-01 d6z]# bzip2 -d -c /tmp/2.txt.bz2 > 4.txt
[root@hf-01 d6z]# ls
1.txt  4.txt
[root@hf-01 d6z]# du -sh 4.txt
1.5M	4.txt
  • bunzip2 1.txt.bz2 > 5.txt 解壓文件,並解壓到當前目錄下,名稱爲5.txt
[root@hf-01 d6z]# bunzip2 1.txt.bz2 > 5.txt
[root@hf-01 d6z]# ls
1.txt  4.txt  5.txt

bzip2壓縮級別

  • bzip2默認壓縮級別爲 9

file查看壓縮文件大小

  • file命令,會知道壓縮文件的類型,大小
[root@hf-01 d6z]# file 1.txt.bz2
1.txt.bz2: bzip2 compressed data, block size = 900k
  • 如果文件名的格式被改錯,或者不知道
    • 在使用less、cat、head查看該文件的時候,會提示「該文件是二進制文件,是否繼續查看呢」
    • 這時候可使用 file命令 去查看,會知道該文件的格式

bzcat查看壓縮文件內容

  • bzcat命令,查看壓縮文件中的內容
    • 格式 bzcat 1.txt.bz2
[root@hf-01 d6z]# bzcat 1.txt.bz2

查看的時候,需注意壓縮文件是否爲空,若爲空,則看不到什麼文件less

相關文章
相關標籤/搜索