tar user guide

 1  tar -f  -f是必備參數並且必須作爲最後一個參數

 

[sroot@AAEP7151shell]# tar -cfcom.tar 1.test 2.test 3.test

[sroot@AAEP7151shell]# ll com.tar

-rw-r--r--.1 sroot root 20480 Jun  1 22:46 com.tar

 

-c表示創建文件  -f表示文件名,兩個是必備參數

 tar -cf archive.tar foo bar

              # Create archive.tar from filesfoo and bar.

 

[sroot@AAEP7151shell]# tar -tfcom.tar

1.test

2.test

3.test

 

-t表示查看歸檔的列表內容

-v, --verbose  列出詳細內容

              verbosely list files processed

 

[sroot@AAEP7151shell]# tar -tvfcom.tar

-rw-r--r--sroot/root    10240 2017-06-01 22:461.test

-rw-r--r--sroot/root        0 2017-06-01 22:422.test

-rw-r--r--sroot/root        0 2017-06-01 22:423.test

 

文檔歸檔後,源文件不消失

 

可以使用通配符

sroot@AAEP7151shell]# tar -cf comq.tar *.test

[sroot@AAEP7151shell]# ll comq.tar

-rw-r--r--.1 sroot root 20480 Jun  1 22:51 comq.tar

 

向歸檔中加新的文件

[sroot@AAEP7151shell]# tar -rvf com.tar menu.sh

menu.sh

[sroot@AAEP7151shell]# tar -tvfcom.tar

-rw-r--r--sroot/root    10240 2017-06-01 22:461.test

-rw-r--r--sroot/root        0 2017-06-01 22:422.test

-rw-r--r--sroot/root        0 2017-06-01 22:423.test

-rwxr-xr-xsroot/root     1000 2017-04-23 18:28menu.sh

 

從歸檔中提取文件

           -xf /PATH/FROM/SOMEFILE.tar 默認展開在當前目錄下

-xf /PATH/FROM/SOMEFILE.tar  -C  制定目

tar -xf output.tar 將歸檔文件的內容提取到當前目錄。

 

[sroot@AAEP7151 shell]# tar -xf com.tar -C /tmp menu.sh

表示從com.tar這個包裏,拿出menu.sh放到/tmp目錄下

 

[sroot@AAEP7151 shell]# ll /tmp/me*

-rwxr-xr-x. 1 sroot root 1000 Apr 23 18:28 /tmp/menu.sh

 

 

[sroot@AAEP7151 shell]# tar -tf comq.tar

1.test

2.test

3.test

[sroot@AAEP7151 shell]# tar -tf com1.tar

homework.sh

[sroot@AAEP7151 shell]# tar -Af com1.tar com.tar

[sroot@AAEP7151 shell]# tar -tf com1.tar

homework.sh

1.test

2.test

3.test

menu.sh

將兩個歸檔合併

 

 

從歸檔中刪除

[sroot@AAEP7151 shell]# tar -f com.tar --delete 2.test

[sroot@AAEP7151 shell]# tar -tf com.tar

1.test

3.test

menu.sh

歸檔之後在壓縮成gz文件用tar -czf命令

czvf

[sroot@AAEP7151shell]# tar -czvf com2.tar.gz 1.test 2.test

1.test

2.test

v表示,都把什麼文件壓縮了,顯示出來

[sroot@AAEP7151shell]# ll com2.tar.gz

-rw-r--r--.1 sroot root 150 Jun  1 23:09 com2.tar.gz

不加v,直接是壓縮,沒有顯示

 

 

[sroot@AAEP7151shell]# tar -xzfcom3.tar.gz

[sroot@AAEP7151shell]# ll *.test

-rw-r--r--.1 sroot root 10240 Jun  1 22:46 1.test

-rw-r--r--.1 sroot root     0 Jun  1 22:42 2.test

 

 

 tar -czf 表示壓縮

Tar -xzf 表示解壓縮

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章