-
-
Save oscarcck/5712323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root @test /root ]# tar [-zxcvfpP] filename | |
[root @test /root ]# tar -N 'yyyy/mm/dd' /path -zcvf target.tar.gz source | |
參數說明: | |
-z :是否同時具有 gzip 的屬性? | |
-x :解開一個壓縮檔案的參數指令! | |
-t :查看 tarfile 裡面的檔案! | |
-c :建立一個壓縮檔案的參數指令 | |
-v :壓縮的過程中顯示檔案! | |
-f :使用檔名,請留意,在 f 之後要立即接檔名喔!不要再加參數! | |
例如使用『 tar -zcvfP tfile sfile』就是錯誤的寫法,要寫成 | |
『 tar -zcvPf tfile sfile』才對喔! | |
-p :使用原檔案的原來屬性(屬性不會依據使用者而變) | |
-P :可以使用絕對路徑 | |
-N :比後面接的日期(yyyy/mm/dd)還要新的才會被打包進新建的檔案中! | |
--exclude FILE:在壓縮的過程中,不要將 FILE 打包! | |
範例: | |
[root @test /root]# tar -cvf directory.tar directory | |
只將目錄整合打包成一個檔案 | |
[root @test /root]# tar -zcvf directory.tar.gz directory | |
除了將目錄打包外,同時以 gzip 壓縮 | |
[root @test /root]# tar -zcvf filename.tar.gz /home/test/* | |
將 /home/test/ 這個目錄下的檔案全部打包並壓縮成為一個 filename.tar.gz 的檔案 | |
[root @test /root]# tar -xvf directory.tar | |
解 tar 的封包,請注意,由於沒有 gzip (.tar 而非 .tar.gz) 的作用,所以只要使用 –xvf 即可!不需要加上 z ,否則會顯示有問題! | |
[root @test /root]# tar -zxvf directory.tar.gz | |
這個就是有加上 gzip 的壓縮的結果!所以需要加上 –z 呦! | |
[root @test /root]# tar –ztvf directory.tar.gz | |
這個 t 可以用來查看 tar 裡面的檔案資訊呢!而不需要將他解開! | |
[root @test /root]# tar -zcvPf home.tar.gz /home | |
則建立起來的壓縮檔內檔案為絕對路徑 | |
請注意,使用這個 P 的參數時,不要將 P 加在 f 後面,因為 | |
f 之後要立即接檔名才行喔! | |
[root @test /root]# tar -N '2002/06/25' -zcvf home.tar.gz /home | |
上面是說 在 /home 這個目錄中,比 2002/06/25 日還要新的檔案才會被打包進入 home.tar.gz 這個檔案中! | |
[root @test /root]# tar -zcvf host.tar.gz / --exclude /mnt --exclude /proc | |
上面是說,將根目錄的所有資料都打包進 host.tar.gz 這個檔案中,但是 /mnt 及 /proc 則不打包! | |
[root @test /root]# tar -cvf - /home | tar -xvf - | |
上面的意思是『將 /home 打包之後,直接解壓縮在 /root 底下!』嘿嘿!不需要再建立一次中間檔案!不過,使用上面的語法最好使用『絕對路徑』,比較不會有問題!這個方式適合不想要建立中間檔案時! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment