文章目錄
- 前言
- 一、歸檔與壓縮的含義
- 1、歸檔
- 2、壓縮
- 二、常見的壓縮格式及命令工具
- 三、tar工具的使用
- 1.tar工具的使用選項
- 2.制作tar包
- 3.解壓tar包
- 四、zip歸檔
- 總結
前言
本篇文章主要介紹了Linux中對檔案的歸檔及壓縮,快來看一看吧!
一、歸檔與壓縮的含義
1、歸檔
將許多零散的檔案整理為一個檔案
檔案總的大小基本不變
2、壓縮
按某種演算法減小檔案所占用空間的大小
恢復時按對應的逆向演算法解壓
二、常見的壓縮格式及命令工具
.gz ? gzip、gunzip
.bz2 ? bzip2、bunzip2
.xz ? xz、unxz
三、tar工具的使用
1.tar工具的使用選項
-c:創建歸檔
-x:釋放歸檔
-f:指定歸檔檔案名稱
-z、-j、-J:呼叫 .gz、.bz2、.xz 格式的工具進行處理
-t:顯示歸檔中的檔案清單
-C:指定釋放路徑
2.制作tar包
格式:tar 選項 /路徑/壓縮包的名字 被壓縮的源資料
[root@localhost ~]# tar -zcf /opt/abc.tar.gz /boot /home
tar: 從成員名中洗掉開頭的“/”
[root@localhost ~]# ls /opt/
[root@localhost ~]# tar -jcf /opt/abc.tar.bz2 /home/ /root/
[root@localhost ~]# ls /opt/
[root@localhost ~]# tar -Jcf /opt/abc.tar.xz /home/ /root/
[root@localhost ~]# ls /opt/
abc.tar.bz2 abc.tar.gz abc.tar.xz B.txt C.txt
3.解壓tar包
格式: tar 選項 /路徑/壓縮包的名字 解壓的路徑
[root@localhost ~]# mkdir /nsd
[root@localhost ~]# tar -xf /opt/abc.tar.gz -C /nsd/ //將/opt/abc.tar.xz解壓到/nsd目錄
[root@localhost ~]# ls /nsd/
[root@localhost ~]# ls /nsd/boot/
[root@localhost ~]# ls /nsd/home/
[root@localhost ~]# tar -xf /opt/abc.tar.bz2 -C /nsd/
[root@localhost ~]# ls /nsd/
[root@localhost ~]# tar -xf /opt/abc.tar.xz //將/opt/abc.tar.xz解壓到當前目錄
[root@localhost ~]# ls
[root@localhost ~]# tar -tf /opt/abc.tar.gz
四、zip歸檔
歸檔+壓縮操作
zip [-r] 備份檔案.zip 被歸檔的檔案…
釋放歸檔+解壓操作
unzip 備份檔案.zip [-d 目標檔案夾]
[root@localhost ~]# zip -r /opt/abc.zip /etc/passwd /home/
[root@localhost ~]# ls /opt/
[root@localhost ~]# mkdir /opt/myzip
[root@localhost ~]# ls /opt/
[root@localhost ~]# unzip /opt/abc.zip -d /opt/myzip/
[root@localhost ~]# ls /opt/
[root@localhost ~]# ls /opt/myzip/
[root@localhost ~]# ls /opt/myzip/etc/
總結
以上就是zip與tar的使用說明,希望對大家有所幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/75031.html
標籤:其他
