打包命令tar

2022-04-10 22:32:28 字數 3050 閱讀 1049

tar是linux下最常用的打包命令,使用tar打出來的包我們常稱為tar包,tar包檔案的命令通常都是以.tar結尾的,也有.gz或.bz2結尾的。

-c,--create      # 新建打包檔案,搭配-v檢視被打包的檔名

-t,--list  # 列出包的內容(有那些檔名)

-x,--extract # 解壓,搭配-c(解壓到特定目錄)

# 注意:-c -t -x不能同時出現在同一命令列中。

-j,--bzip2 # 通過bzip2的支援進行壓縮和解壓縮,檔名最好為*.tar.bz2

-z,--gzip # 通過gzip的支援進行壓縮或解壓縮,檔名最好為*.tar.gz

-v,--verbose # 顯示詳細

-f filename # 接要被處理的檔案,建議:-f 單獨使用

-c,--directory = dir  # 解壓到特定目錄dir

-p # 保留備份資料檔案的許可權和屬性,常用於備份重要的資料

-p # 保留打包檔案的根目錄

-x, --exclude-from=file # 排除指定檔案

引數組合:將a.txt b.txt c.txt d.txt這四個檔案打包成abcd.tar.bz2。

#tar -cvj -f abcd.tar.bz2 a.txt b.txt c.txt d.txt

詳情:

[@tc_57_161 lyy]# ll

total

28-rw-r--r-- 1 root root 10240 dec 12

18:50

a.txt

-rw-r--r-- 1 root root 10 dec 12

18:48

b.txt

-rw-r--r-- 1 root root 10 dec 12

18:49

c.txt

-rw-r--r-- 1 root root 10 dec 12

18:49

d.txt

-rw-r--r-- 1 root root 196 dec 12

18:51 new.tar

.bz2

drwxr-xr-x 3 root root 24 nov 23

19:32

project

drwxr-xr-x 2 root root 135 dec 1

15:52

test

[@tc_57_161 lyy]#

tar -cvj -f abcd.tar

.bz2 a.txt b.txt c.txt d.txt

a.txt

b.txt

c.txt

d.txt

[@tc_57_161 lyy]# ll

total

32-rw-r--r-- 1 root root 196 dec 16

21:18 abcd.tar

.bz2

-rw-r--r-- 1 root root 10240 dec 12

18:50

a.txt

-rw-r--r-- 1 root root 10 dec 12

18:48

b.txt

-rw-r--r-- 1 root root 10 dec 12

18:49

c.txt

-rw-r--r-- 1 root root 10 dec 12

18:49

d.txt

-rw-r--r-- 1 root root 196 dec 12

18:51 new.tar

.bz2

drwxr-xr-x 3 root root 24 nov 23

19:32

project

drwxr-xr-x 2 root root 135 dec 1

15:52 test

[@tc_57_161 lyy]# tar -jtv -f abcd.tar

.bz2

-rw-r--r-- root/root 10240

2017-12-12

18:50

a.txt

-rw-r--r-- root/root 10

2017-12-12

18:48

b.txt

-rw-r--r-- root/root 10

2017-12-12

18:49

c.txt

-rw-r--r-- root/root 10

2017-12-12

18:49 d.txt

命令:

# tar -jxv -f abcd.tar.bz2 -c mytar/

# -c 解壓到哪個目錄

詳情:

[@tc_57_161 lyy]# mkdir

mytar

[@tc_57_161 lyy]#

tar -jxv -f abcd.tar.bz2 -c mytar/a.txt

b.txt

c.txt

d.txt

[@tc_57_161 lyy]#

ls -l mytar/total

24-rw-r--r-- 1 root root 10240 dec 12

18:50

a.txt

-rw-r--r-- 1 root root 10 dec 12

18:48

b.txt

-rw-r--r-- 1 root root 10 dec 12

18:49

c.txt

-rw-r--r-- 1 root root 10 dec 12

18:49

d.txt

[@tc_57_161 lyy]#

tar 打包命令

tar 將多個目錄或檔案打包成乙個檔案,並可透gzip和bzip2進行壓縮.語法格式 tar a c d r t u x options pathname 引數說明 c 建立打包檔案,可搭配 v檢視過程中被打包的檔名 t 檢視打包檔案有哪些檔名 x 解打包或解壓縮的功能,可搭配 c在特定目錄解開 j...

打包命令 tar

c 建立乙個新的歸檔檔案 x 對歸檔檔案解壓 t 檢視歸檔檔案裡的檔案 v 顯示執行過程 f 指定包名 z 使用gzip壓縮歸檔檔案 tar.gz j 使用bzip2壓縮歸檔檔案 tar.gz2 j 使用xz壓縮歸檔後的檔案 tar.xz c 指定壓縮位置 x 排除多個檔案 h 打包軟鏈結 tar....

打包壓縮命令tar

之前介紹的gzip和bzip2都是壓縮命令,但是它們只可以壓縮單個檔案。如果我們需要壓縮乙個目錄中的所有檔案的話,就需要使用tar。tar的使用簡單,關鍵是做好引數的設定。幾個常用的引數配置如下 1 tar jcv f 壓縮檔案名.tar.bz2 被壓縮檔案名 第乙個檔名是壓縮檔案名,這個需要使用者...