tar命令簡介-常用功能
tar命令是linux中非常實用的一個命令,是非常基礎以及常用的。
本文只做非常簡單和常用命令的介紹。如果需要了解完整用法,可以在linux終端中輸入
man tar
或者tar --useage
或者tar --help
。
- tar命令一定要指定引數才能正確執行。
tar命令的語法
tar [options][files]
例如:
tar zxvf test.tar.gz
, 將壓縮包test.tar.gz解壓tar cvf a.tar 1.txt 2.txt
, 將1.txt和2.txt壓縮到a.tar中tar xvf a.tar
,解壓縮a.tartar tf a.tar
The options used most often with tar are as follows:
c Creates a new backup,overwriting any files already on the backup destination.
x Extracts files from backup media.
t Lists the contents of backup media.
v Displays the name of each file being processed.
f Creates backups on a specified device.
u Adds files to the backup if they are not already there,or if they have been modified since they were last written on the backup.
常用的引數
- c 建立一個壓縮包
- x 解壓一個壓縮包
- v 執行命令過程中顯示冗餘(詳細)資訊
- f 指定要被執行的檔案
- z 呼叫gzip聯合來對檔案進行壓縮、解壓
- r 追加檔案到壓縮包中
最常用的引數組合
- zcvf 聯合gzip壓縮檔案並顯示詳細資訊,壓縮包名稱應該為*.tar.gz
- zxvf 聯合gzip解壓檔案並顯示詳細資訊,被解壓的檔名稱應為*.tar.gz
- cvf 壓縮檔案並顯示詳細資訊,壓縮包名稱應該為*.tar
- zvf 解壓檔案並顯示詳細資訊,被解壓的檔名稱應為*.tar
- tvf 顯示壓縮包中的檔案詳細列表
- vf 顯示壓縮包中的檔案