日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux运维:常用的压缩解压缩命令(zip、tar)

發布時間:2025/3/19 linux 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux运维:常用的压缩解压缩命令(zip、tar) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 壓縮類型
  • zip類型
    • 1、zip壓縮
    • 2、unzip解壓縮
  • tar類型
    • 1、.tar壓縮和解壓
    • 2、.tar.gz壓縮和解壓
    • 3、.tar.bz2壓縮和解壓
    • 4、.tar.Z壓縮和解壓
    • 5、統一解壓方式
  • 幾種格式壓縮大小對比

壓縮類型

Linux下常見的壓縮格式有以下幾類,針對以下幾類進行壓縮解壓縮:

zip tar.gz tar.bz2 tar.xz tar.Z

zip類型

首先,如果是Linux下安裝了zip命令包的話可以進行zip的解壓縮。
zip的命令格式:

[root@hadoop-slave3 bin]# zip --help Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license. Zip 3.0 (July 5th 2008). Usage: zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]The default action is to add or replace zipfile entries from list, whichcan include the special name - to compress standard input.If zipfile and list are omitted, zip compresses stdin to stdout.-f freshen: only changed files -u update: only changed or new files-d delete entries in zipfile -m move into zipfile (delete OS files)-r recurse into directories -j junk (don't record) directory names-0 store only -l convert LF to CR LF (-ll CR LF to LF)-1 compress faster -9 compress better-q quiet operation -v verbose operation/print version info-c add one-line comments -z add zipfile comment-@ read names from stdin -o make zipfile as old as latest entry-x exclude the following names -i include only the following names-F fix zipfile (-FF try harder) -D do not add directory entries-A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)-T test zipfile integrity -X eXclude eXtra file attributes-y store symbolic links as the link instead of the referenced file-e encrypt -n don't compress these suffixes-h2 show more help

常用的壓縮命令:

1、zip壓縮

將當前目錄下txt壓縮到test.zip中

zip -r test.zip *.txt

2、unzip解壓縮

將test.zip解壓縮到./testunzip/目錄

unzip test.zip -d ./testunzip/

tar類型

常用壓縮命令

1、.tar壓縮和解壓

將目錄里所有txt文件打包成test.tar

tar -cvf test.tar *.txt

解壓縮:

tar -xvf test.tar

2、.tar.gz壓縮和解壓

將目錄里所有txt文件打包成test.tar后,并且將其用gzip壓縮,生成一個gzip壓縮過的包,命名為test.tar.gz

tar -czf test.tar.gz *.txt

解壓縮:

tar -zxvf test.tar.gz

3、.tar.bz2壓縮和解壓

將目錄里所有txt文件打包成test.tar后,并且將其用bzip2壓縮,生成一個bzip2壓縮過的包,命名為test.tar.bz2

tar -cjf test.tar.bz2 *.txt

解壓縮:

tar -jxvf test.tar.bz2

4、.tar.Z壓縮和解壓

將目錄里所有txt文件打包成test.tar后,并且將其用compress壓縮,生成一個umcompress壓縮過的包,命名為test.tar.Z

tar -cZf test.tar.Z *.txt

解壓縮:

tar -Zxvf test.tar.Z

5、統一解壓方式

事實上, 從1.15版本開始tar就可以自動識別壓縮的格式,故不需人為區分壓縮格式就能正確解壓

tar -xvf test.tar tar -xvf test.tar.gz tar -xvf test.tar.bz2 tar -xvf test.tar.xz tar -xvf test.tar.Z

幾種格式壓縮大小對比

壓縮前文件大小:

[root@hadoop-master ziptest]# ls -lht 總用量 16K -rwxr-xr-x. 1 root root 1.3K 12月 19 16:08 test3.txt -rwxr-xr-x. 1 root root 1.3K 12月 19 16:07 test2.txt -rwxr-xr-x. 1 root root 1.3K 12月 19 16:07 test1.txt -rwxr-xr-x. 1 root root 1.3K 12月 19 16:06 vi_test.txt

幾種壓縮格式壓縮后:

[root@hadoop-master ziptest]# ls -lh 總用量 28K -rw-r--r--. 1 root root 10K 12月 19 17:22 test.tar -rw-r--r--. 1 root root 1.2K 12月 19 17:22 test.tar.bz2 -rw-r--r--. 1 root root 960 12月 19 17:22 test.tar.gz -rw-r--r--. 1 root root 3.0K 12月 19 17:22 test.tar.Z -rw-r--r--. 1 root root 3.6K 12月 19 17:23 test.zip

總結

以上是生活随笔為你收集整理的Linux运维:常用的压缩解压缩命令(zip、tar)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。