1. 打包tar
打包表示把一堆文件變成一個
tar ####打包工具
-f ####指定生成包的名字
-c ####創建包
-v ####顯示創建過程
-t ####查看包中內容
-x ####解包
-r ####添加文件到包中
--delete filename ##刪除包中指定文件
--get filename ?##取出包中指定文件
? ? ? ? ?cf
? ? ? ? ?fr
? ? ? ? ?cvf ? ?等組合使用
2. 壓縮
gzip
gzip xxxx.tar =====> xxxx.tar.gz ##壓縮
gunzip xxxx.tar.gz =====> xxxx.tar ##解壓
tar zcvf xxxx.tar.gz 目標文件 ##打包壓縮文件
tar zxvf xxxx.tar.gz ###xxxx.tar.gz===>xxxx
bz2
bzip2 xxxx.tar =====> xxxx.tar.bz2 ##壓縮
bunzip2 xxxx.tar.bz2 =====> xxxx.tar ##解壓
tar jcvf xxxx.tar.bz2 目標文件 ##打包壓縮文件
tar jxvf xxxx.tar.bz2 ###xxxx.tar.bz2===>xxxx
xz
xz xxxx.tar =====> xxxx.tar.xz ? ? ?##壓縮
unxz xxxx.tar.xz =====> xxxx.tar ? ?##解壓
tar Jcvf xxxx.tar.xz 目標文件 ? ?##打包壓縮文件
tar Jxvf xxxx.tar.xz ? ? ? ? ? ? ? ?###xxxx.tar.xz===>xxxx
zip
zip -r xxx.tar.zip xxx.tar ? ?###壓縮
unzip xxx.tar.zip ? ?###解壓
例:
1.打包文件
[root@localhost test]# touch file{1..10}
[root@localhost test]# tar -cf test.tar ?*
[root@localhost test]# ls
file1 ?file10 ?file2 ?file3 ?file4 ?file5 ?file6 ?file7 ?file8 ?file9 ?test.tar
2.解壓文件
[root@localhost test]# mkdir test1
[root@localhost test]# cd test1
[root@localhost test1]# tar xf ../test.tar?
[root@localhost test1]# ls
3.gzip打包壓縮
[root@localhost test]# ls
file1 ?file10 ?file2 ?file3 ?file4 ?file5 ?file6 ?file7 ?file8 ?file9
[root@localhost test]# tar -zcvf test.tar *
file1
file10
file2
file3
file4
file5
file6
file7
file8
file9
[root@localhost test]# ls
file1 ?file10 ?file2 ?file3 ?file4 ?file5 ?file6 ?file7 ?file8 ?file9 ?test.tar
4.解gzip壓縮包
[root@localhost test]# ls
file1 ?file10 ?file2 ?file3 ?file4 ?file5 ?file6 ?file7 ?file8 ?file9 ?test.tar
[root@localhost test]# mkdir test2
[root@localhost test]# cd test2/
[root@localhost test2]# tar -zxvf ../test.tar?
file1
file10
file2
file3
file4
file5
file6
file7
file8
file9
[root@localhost test2]# ls
file1 ?file10 ?file2 ?file3 ?file4 ?file5 ?file6 ?file7 ?file8 ?file9
轉載于:https://blog.51cto.com/willis/1846719