tar工具(打包,压缩)
=========================
tar打包工具
-c:表示建立一个tar包或者压缩文件包
-x:表示解包或者解压缩
-v:表示可视化
-f: 后面跟文件名(即-f filename,表示打包后(压缩后)的文件名为filename,或者解包(解压缩)的文件名为filename)
-z;表示同时用gzip压缩
-j;表示同时用bzip2压缩
-J;表示同时用xz压缩
-t;表示查看tar包里的文件
--exclude filename: 表示在打包或者压缩时,不要将filename文件包括在内。
示例;
[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.txt
dir1/
dir1/dir2/
dir1/dir2/2.txt
dir1/1.txt
1.txt
3.txt
tar打包并压缩
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.tar