tar是常用的解壓縮指令,常用參數
- -c 創建一個壓縮包
- v 顯示壓縮的詳細信息
- -z 壓縮,如果沒有只是打包
- -f 壓縮后的目標文件名
- -x解壓
- -C解壓到指定目錄下
實例
- 把所有名為cc*.txt的文件打包到file.tar下
[root@centoscc cc]# tar -cf file.tar cc*.txt [root@centoscc cc]# ls -l 總用量 60 ... -rw-r--r--. 1 root root 10240 12月 24 19:11 file.tar ...
- 把文件root1.txt增加到file.tar文件中
[root@centoscc cc]# tar -rf file.tar root1.txt
- 更新file.tar包中的root1.txt文件
[root@centoscc cc]# tar -uf file.tar root1.txt
- 列出包中的文件
[root@centoscc cc]# tar -tf file.tar cc4.txt cc.txt root1.txt
- 解出包中內容到同一目錄下
[root@centoscc cc1]# ls -l 總用量 12 drwx--x--x. 3 root root 18 12月 20 16:25 cc1 drwxr-xr-x. 2 root root 6 12月 20 16:24 cc11 -rw-r--r--. 1 root root 10240 12月 24 19:11 file.tar [root@centoscc cc1]# tar -xf file.tar [root@centoscc cc1]# ls -l 總用量 24 drwx--x--x. 3 root root 18 12月 20 16:25 cc1 drwxr-xr-x. 2 root root 6 12月 20 16:24 cc11 -rw-r--r--. 1 root root 16 12月 20 21:19 cc4.txt -rw-r--r--. 1 root root 15 12月 20 21:21 cc.txt -rw-r--r--. 1 root root 10240 12月 24 19:11 file.tar -rw-r--r--. 1 root root 16 12月 22 20:37 root1.txt
- 解出包中內容到指定目錄下(該目錄要先創建,否則會報錯)
[root@centoscc cc1]# tar -xvf file.tar -C file1 cc4.txt cc.txt root1.txt [root@centoscc cc1]# cd file1 [root@centoscc file1]# ls -l 總用量 12 -rw-r--r--. 1 root root 16 12月 20 21:19 cc4.txt -rw-r--r--. 1 root root 15 12月 20 21:21 cc.txt -rw-r--r--. 1 root root 16 12月 22 20:37 root1.txt
tar調用其他壓縮程序
常用指令:
- z:把tar包壓縮成.tar.gz格式:
# tar -czf file1.tar.gz cc*.txt 解壓:# tar -xzf file1.tar.gz
- Z:把tar包壓縮成.tar.Z
- j:把tar包壓縮成 .tar.bz2