日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

打包和壓縮

將文件或文件夾合并成一個包,然后通過壓縮算法進行數據壓縮,減小包的體積,方便網絡傳輸。

windows:
  zip
  rar

linux:
  zip
  tar
  gz
  bz2
  tar.gz
  tar.bz2

壓縮算法:
  gzip
  bzip2

zip

是一個Windows和Linux中常用打包壓縮工具,支持的壓縮算法是zip。

zip工具需要安裝
  yum install zip

zip壓縮一個文件

# 格式
  zip [參數] 壓縮包名稱  文件路徑

[root@abc ~]# zip 123.zip 123.log 
  adding: 123.log (deflated 87%)
[root@abc ~]# ls -l

zip壓縮文件夾

# 需要一個-r參數去遞歸壓縮文件夾下的所有內容
[root@abc ~]# zip -r dir.zip dir/
  adding: dir/ (stored 0%)
  adding: dir/one/ (stored 0%)
  adding: dir/123.log (deflated 87%)

zip的靜默輸出

# -q:參數就是不輸出任何打包信息
[root@abc opt]# zip -r -q etc.zip /etc/
[root@abc opt]# ls -l

zip解壓命令(unzip)

# 格式
  unzip [參數] 壓縮包路徑

# unzip解壓命令只能解壓由zip打包的壓縮文件
[root@abc ~]# unzip dir.zip 
Archive:  dir.zip
  inflating: dir/123.log             
[root@abc ~]# 

# 其他壓縮包由unzip解壓時隨即報錯。
[root@abc opt]# unzip nginx-.tar.gz
Archive:  nginx-.tar.gz
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of nginx-.tar.gz or
        nginx-.tar.gz.zip, and cannot find nginx-.tar.gz.ZIP, period.


# 查看壓縮包中壓縮那些內容,不解壓?
# 只查看壓縮包內容不解壓需要使用 -l 參數
[root@abc opt]# unzip -l dir.zip 
Archive:  dir.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  03-11-2021 12:04   dir/
---------                     -------
        0                     1 file

# 解壓到指定目錄(-d)
[root@abc ~]# unzip -d /root/  etc.zip 
[root@abc opt]# cd /root/
[root@abc ~]# ls
]        anaconda-ks.cfg  dir.zip  index.html           test.pdf.gz  xxxeth0xxx           系統優化.md
123.log  demo.txt         etc      nginx-0.1.22.tar.gz  test.txt     上傳與下載.md
123.zip  dir              eth0xxx  test                 xxxeth0      文件管理_(高級).pdf

# 靜默輸出(-q)
[root@abc ~]# rm -rf etc
[root@abc ~]# unzip -q -d /root/ /opt/etc.zip 
[root@abc ~]# ls -l

tar

tar壓縮支持多種壓縮算法

tar.gz gzip (用的最多)

tar.bz2 bzip2

gzip

通過gzip壓縮算法,將文件壓縮一定體積,有利于傳輸, 不支持打包

[root@abc ~]# ls -l
total 4828
-rw-r--r--   1 root root  244977 Mar 10 12:12 index.html
[root@abc ~]# gzip index.html 
[root@abc ~]# ls -l
gzip壓縮一個目錄
[root@abc etc]# gzip -r /etc
[root@abc etc]# ls

gzip解壓(-d)

[root@abc ~]# ls -l
-rw-r--r--   1 0 0   22652 Mar 10 12:12 index.html.gz
[root@abc ~]# gzip -d index.html.gz 
[root@abc ~]# ls -l

bzip2

使用bzip2 壓縮算法來壓縮一定體積的文件。

[root@abc ~]# ls -l
total 4828
-rw-r--r--   1 root root  646165 Mar  9 10:31 123.log     
[root@abc ~]# bzip2 123.log 
[root@abc ~]# ls -l
total 4240
-rw-r--r--   1 root root       0 Mar 10 12:04 ]

bzip2解壓(-d)

bzip2解壓是針對于bzip2壓縮的壓縮包來進行解壓。

[root@abc ~]# ls -l
total 4240
-rw-r--r--   1 root root   42210 Mar  9 10:31 123.log.bz2
[root@abc ~]# bzip2 -d 123.log.bz2 
[root@abc ~]# ls -l

tar

tar其實是一個打包工具,不具備壓縮功能,但是可以使用參數調用壓縮工具來進行解壓。

tar參數
  -c : 創建壓縮
  -f ; 指定壓縮包名稱
  -z : 使用gzip壓縮工具進行壓縮
  -j : 使用bzip2壓縮工具進行壓縮
  -J : 使用xz壓縮工具進行壓縮
  -t : 顯示壓縮包內容,不解壓
  -v : 顯示壓縮過程
  -P : 允許使用絕對路徑進行壓縮
  -x : 解壓
  -C : 指定解壓路徑
  -h : 打包軟連接
  --exclude : 排除某些文件
  --exclude-from :
參數
  • -c : 創建壓縮包

  • -f : 指定壓縮包名稱

[root@abc ~]# tar -c -f test.tar 123.log 
[root@abc ~]# ls -l
  • -z : 指定使用gzip壓縮工具進行壓縮

[root@abc ~]# tar  -c -z -f test-one.tar 123.log 
[root@abc ~]# ls -l 
total 5084
-rw-r--r--   1 root root   85279 Mar 11 15:56 test-one.tar

# 注:使用-z參數,不會自動添加.gz后綴

[root@abc ~]# tar -c -z -f anaconda.tar.gz  anaconda-ks.cfg 
[root@abc ~]# ls -l
  • -j : 指定使用bzip2壓縮工具進行壓縮

[root@abc ~]# tar -c -j -f 123-bask-one.tar 123.log 
[root@abc ~]# ls -l
  • -J : 指定使用xz壓縮工具進行壓縮

[root@abc test-tar]# tar -c -J  -f etc.tar.xz /etc/
[root@abc ~]# ls -l
  • -t : 查看壓縮包內容

[root@abc ~]# tar -t -f 123-bak.tar.bz2 
123.log
[root@abc ~]#
  • -v : 顯示壓縮包壓縮過程

[root@abc ~]# tar -x -v -f etc.tar -C /opt/
  • -P : 允許使用絕對路徑進行打包

[root@abc ~]# tar -c -P -f 123-three.tar /etc/passwd
[root@abc ~]# tar -c -f 123-three.tar /etc/passwd
tar: Removing leading `/' from member names
[root@abc ~]#
  • -x : 解壓

# tar解壓是按照原來的路徑進行解壓
[root@abc test]# tar -x -f etc.tar 

# tar會自動識別壓縮功能
  • -C : 指定解壓路徑

[root@abc ~]# tar -x -f etc.tar -C /opt/
tar: Removing leading `/' from member names
[root@abc ~]# cd /opt/
[root@abc opt]# ls
abc23  dir  dir.zip  etc  nginx-0.1.22.tar.gz  nginx-.tar.gz  xxx
[root@abc opt]#
  • –exclude : 排除某些文件

[root@abc test-tar]# tar -c -f abc.tar ./* --exclude=abc7 --exclude=abc5   --exclude=abc1 
[root@abc test-tar]# tar -t -f abc.tar 
./abc2
./abc3
./abc4
./abc6
./abc8
./abc9
[root@abc test-tar]#
  • –exclude-from : 根據某個文件列表排除多個文件

[root@abc test-tar]# cat list.txt 
abc995
abc996
abc997
abc998
abc999
[root@abc test-tar]# tar -c -f abc.tar ./* --exclude-from=list.txt
  • -h : 打包軟連接

[root@abc test-tar]# tar -c -h -f bin-h.tar /bin

以上就是linux文件打包與壓縮的方法是什么的詳細內容.

分享到:
標簽:壓縮 打包 文件 方法 服務器
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定