Unit8 對檔案進行歸檔 壓縮

2021-09-09 04:57:55 字數 4903 閱讀 7614

定義:就是把多個檔案變成乙個歸檔檔案

目的:加快資料的傳輸速度

tar表示打包

c->建立乙個壓縮檔案的引數指令

f->指定歸檔檔案名稱

cf一般連著用

[root@vm138 mnt]# ls dir    #在dir目錄下建立5個檔案

file1  file2  file3  file4  file5

[root@vm138 mnt]# tar cf dir.tar dir  #將dir打包成dir.tar

[root@vm138 mnt]# ls

dir  dir.tar

[root@vm138 mnt]# du -sh dir.tar #可以檢視dir.tar的大小

12k dir.tar

[root@vm138 mydir]# ls

dir.tar

[root@vm138 mydir]# tar tf dir.tar    #顯示文當中的內容

mnt/

mnt/file1

mnt/file2

mnt/file3

mnt/file4

mnt/file5

[root@vm138 mydir]# tar xf dir.tar #解開乙個歸檔檔案

[root@vm138 mydir]# ls

dir.tar  mnt

[root@vm138 mydir]# ls mnt

file1  file2  file3  file4  file5

##建立新的檔案和目錄

[root@vm138 mydir]# touch newfile

[root@vm138 mydir]# mkdir rsy

[root@vm138 mydir]# touch rsy/myfile

[root@vm138 mydir]# touch rsy/others

[root@vm138 mydir]# ls

dir.tar  newfile  rsy

[root@vm138 mydir]# tar rf dir.tar newfile   #向歸檔檔案中加入新的檔案

[root@vm138 mydir]# tar rf dir.tar rsy       #向歸檔檔案中加入新的目錄

[root@vm138 mydir]# tar tf dir.tar

mnt/

mnt/file1

mnt/file2

mnt/file3

mnt/file4

mnt/file5

newfile

rsy/

rsy/myfile

rsy/others

[root@vm138 mydir]# tar -f dir.tar --delete newfile  #刪除歸檔檔案中加入檔案或目錄

[root@vm138 mydir]# tar tf dir.tar  

mnt/

mnt/file1

mnt/file2

mnt/file3

mnt/file4

mnt/file5

rsy/

rsy/myfile

rsy/others

[root@vm138 mydir]# rm -rf rsy

[root@vm138 mydir]# ls

dir.tar  newfile

[root@vm138 mydir]# tar -f dir.tar --get rsy/others   #取出歸檔檔案中的rsy/others

[root@vm138 mydir]# ls

dir.tar  newfile  rsy

[root@vm138 mydir]# ls rsy

others

是一種通過特定演算法來減少計算機檔案大小機制,可以使檔案通過較慢的網際網路實現更快的傳輸,並減少磁碟的占用空間。

壓縮的方法主要有三種

穩定性較差,只適合壓縮純文字文件

zip -r etc.tar.zip etc.tar  #壓縮

unzip etc.tar.zip       #解壓

[root@vm80 mnt]# du -sh etc.tar

30m etc.tar

[root@vm80 mnt]# zip -r etc.tar.zip etc.tar   ##壓縮已歸檔的tar檔案

adding: etc.tar (deflated 72%)

[root@vm80 mnt]# du -sh etc.tar.zip

8.4m etc.tar.zip

[root@vm80 mnt]# ls

etc  etc.tar.zip

[root@vm80 mnt]# unzip etc.tar.zip    ##解壓縮

archive:  etc.tar.zip

inflating: etc.tar                 

[root@vm80 mnt]# ls

etc  etc.tar  etc.tar.zip

gzip etc.tar       #壓縮

gunzip etc.tar.gz  #解壓

[root@vm80 mnt]# ls

etc  etc.tar

[root@vm80 mnt]# gzip etc.tar

[root@vm80 mnt]# ls

etc  etc.tar.gz

[root@vm80 mnt]# gunzip etc.tar.gz

[root@vm80 mnt]# ls

etc  etc.tar

進行壓縮最慢了,但是壓縮後比較小

xz etc.tar #壓縮成xz格式

unxz etc.tar.xz #解壓xz格式的壓縮包

[root@vm80 mnt]# xz etc.tar

[root@vm80 mnt]# du -sh etc.tar.xz

5.7m etc.tar.xz

[root@vm80 mnt]# ls

etc  etc.tar.xz

[root@vm80 mnt]# unxz etc.tar.xz

[root@vm80 mnt]# ls

etc  etc.tar

只適合於壓縮純文字檔案

[root@server88 mnt]# ls

etc  etc.tar

[root@server88 mnt]# du -sh etc.tar

30m etc.tar

[root@server88 mnt]# bzip2 etc.tar    ##壓縮

[root@server88 mnt]# du -sh etc.tar.bz2

7.0m etc.tar.bz2

[root@server88 mnt]# ls

etc  etc.tar.bz2

[root@server88 mnt]# bunzip2 etc.tar.bz2    ##解壓

[root@server88 mnt]# ls

etc  etc.tar

以gz格式直接進行打包壓縮

[root@server88 mnt]# tar -zcf etc.tar.gz etc/

[root@server88 mnt]# ls

etc  etc.tar.gz

[root@server88 mnt]# rm -rf etc

[root@server88 mnt]# ls

etc.tar.gz

[root@server88 mnt]# tar -zxf etc.tar.gz

[root@server88 mnt]# ls

etc  etc.tar.gz

以xz格式直接進行打包壓縮

[root@server88 mnt]# tar -jcf etc.tar.xz etc

[root@server88 mnt]# ls

etc  etc.tar.xz

[root@server88 mnt]# du -sh etc.tar.xz

5.7m etc.tar.xz

[root@server88 mnt]# rm -rf etc

[root@server88 mnt]# ls

etc.tar.xz

[root@server88 mnt]# tar -jxf etc.tar.xz

[root@server88 mnt]# ls

etc  etc.tar.xz

3 6對檔案進行歸檔和壓縮處理

3.6對檔案進行歸檔和壓縮處理 檔案的壓縮與解壓縮 常見的壓縮副檔名 gz gzip程式壓縮的檔案 bz2 bzip2程式壓縮的檔案 tar tar程式打包的資料,並沒有經過壓縮 tar.gz tar程式打包的檔案,其中經過gzip的壓縮 tar.bz2 tar程式打包的檔案,其中經過bzip2的壓...

Linux對檔案進行歸檔和壓縮處理

常見的壓縮檔案的副檔名 gz gzip 程式壓縮的檔案 bz2 bzip2 程式壓縮的檔案 tar tar程式打包的資料,並沒有經過壓縮 tar.gz tar 程式打包的檔案,其中經過gzip的壓縮 tar.bz2 tar 程式打包的檔案,其中經過bzip2的壓縮 2.1 gzip 使用gzip壓縮...

對檔案進行歸檔的命令為

a dd b cpio c gzip d tar tar命令 root linux tar cxtzjvfppn 檔案與目錄 引數 c 建立乙個壓縮檔案的引數指令 create 的意思 x 解開乙個壓縮檔案的引數指令!t 檢視 tarfile 裡面的檔案!特別注意,在引數的下達中,c x t 僅能存...