tar打包工具linux
-c:表示創建一個tar包或者壓縮文件包
-x:表示解包或者解壓縮
-v:表示可視化
-f: 後面跟文件名(即-f filename,表示打包後(壓縮後)的文件名爲filename,或者解包(解壓縮)的文件名爲filename)
-z;表示同時用gzip壓縮
-j;表示同時用bzip2壓縮
-J;表示同時用xz壓縮工具
-t;表示查看tar包裏的文件blog
--exclude filename: 表示在打包或者壓縮時,不要將filename文件包括在內。ip
示例;可視化
[root@aminglinux yasuo]# ls
1.txt 1.txt.gz 1.txt.new 1.txt.zip 2.txt.gz 3.txt dir1 dir1.zip
[root@aminglinux yasuo]# tar -cvf new.tar dir1 1.txt 3.txt
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
1.txt
3.txt
[root@aminglinux yasuo]# ls
1.txt 1.txt.gz 1.txt.new 1.txt.zip 2.txt.gz 3.txt dir1 dir1.zip new.tar
[root@aminglinux yasuo]# tar -tf new.tar
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
1.txt
3.txt
[root@aminglinux yasuo]# tar -xvf new.tar
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
1.txt
3.txt
[root@aminglinux yasuo]# ls
1.txt 1.txt.gz 1.txt.new 1.txt.zip 2.txt.gz 3.txt dir1 dir1.zip new.tar打包
[root@aminglinux yasuo]# tar -cvf new.tar --exclude dir3 dir1 1.txt 3.txtfile
dir1/
dir1/dir2/
dir1/dir2/2.txt
dir1/1.txt
1.txt
3.txtim
tar打包並壓縮d3
1,打包的同時使用gzip壓縮
示例:
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 new.tar
[root@aminglinux yasuo]# tar -czvf dir1.tar.gz dir1
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.gz new.tar
[root@aminglinux yasuo]# tar -tf dir1.tar.gz
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# rm -rf dir1
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1.tar.gz new.tar
[root@aminglinux yasuo]# tar -zxvf dir1.tar.gz
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.gz new.tar
2,打包的同時使用bzip2壓縮
示例:
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.gz new.tar
[root@aminglinux yasuo]# tar -jcvf dir1.tar.bz2 dir1
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.bz2 dir1.tar.gz new.tar
[root@aminglinux yasuo]# tar -tf dir1.tar.bz2
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# tar -jxvf dir1.tar.bz2
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.bz2 dir1.tar.gz new.tar
3,打包的同時使用xz壓縮
示例:
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.bz2 dir1.tar.gz new.tar
[root@aminglinux yasuo]# tar -Jcvf dir1.tar.xz dir1
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.bz2 dir1.tar.gz dir1.tar.xz new.tar
[root@aminglinux yasuo]# tar -tf dir1.tar.xz
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# rm -rf dir1
[root@aminglinux yasuo]# tar -Jxvf dir1.tar.xz
dir1/
dir1/dir2/
dir1/dir2/dir3/
dir1/dir2/dir3/3.txt
dir1/dir2/2.txt
dir1/1.txt
[root@aminglinux yasuo]# ls
1.txt 2.txt 3.txt dir1 dir1.tar.bz2 dir1.tar.gz dir1.tar.xz new.tarimg