tar目录概要
- tar -cvf 123.tar 123
- tar -cvf aming.tar 1.txt 123
- tar -xvf aming.tar
- tar -tf aming.tar
- tar -cvf aming.tar --exclude 1.txt --exclude 2 123
网络小知识
- 带宽的单位:比特(Byte)
- 100兆网卡跑满,应该是12.5兆字节每秒(这是传输速度)——>这是理论值
tar打包目录
- 打包对于文件大小无太大变化,可是多少会存在一些微小的变化
- 若是每一个小文件小于4K(小于一个块的大小),文件只有1K、2K、3K(未超过4K),有一万个相似的文件,就须要4000K(40兆),但打包这些小文件就会相加,最后有可能只有十几兆
- tar -cvf hf.tar hf/ 把hf目录打包成hf.tar,其中 / 符号可省略
- c 表示建立,v 表示可视化,看到建立的过程,f 后跟tar打包的名称——>v可省略,但cf必须有
[root@hf-01 d6z]# ls
1.txt 1.txt.zip 4.txt 5.txt 8.xt hafe.zip hf
[root@hf-01 d6z]# tar -cvf hf.tar hf/
hf/
hf/han/
hf/han/hanfeng/
hf/han/hanfeng/66.txt
hf/han/hanfeng/1.txt
hf/han/wu.txt
hf/1.txt
[root@hf-01 d6z]#
- 若已经打包,再次去从新打包,会直接覆盖以前的打包文件,而且没有任何提示
[root@hf-01 d6z]# tar -cf hf.tar hf/
[root@hf-01 d6z]# ls
1.txt 1.txt.zip 4.txt 5.txt 8.xt hafe.zip hf hf.tar
[root@hf-01 d6z]#
tar解包
- tar -xvf hf.tar 把hf.tar包解开——>默认覆盖以前的物件,无任何提示
[root@hf-01 d6z]# tar -xvf hf.tar
hf/
hf/han/
hf/han/hanfeng/
hf/han/hanfeng/66.txt
hf/han/hanfeng/1.txt
hf/han/wu.txt
hf/1.txt
[root@hf-01 d6z]# ls
1.txt 1.txt.zip 4.txt 5.txt 8.xt hafe.zip hf hf.tar
tar打包目录和文件
- tar -cvf han.tar hf/ 1.txt 4.txt 把文件和目录一块儿打包成han.tar
[root@hf-01 d6z]# tar -cvf han.tar hf/ 1.txt 4.txt
hf/
hf/han/
hf/han/hanfeng/
hf/han/hanfeng/66.txt
hf/han/hanfeng/1.txt
hf/han/wu.txt
hf/1.txt
1.txt
4.txt
[root@hf-01 d6z]# ls
1.txt 1.txt.zip 4.txt 5.txt 8.xt hafe.zip han.tar hf hf.tar
tar查看打包文件中的文件列表
- tar -tf han.tar 查看han.tar中的文件列表
[root@hf-01 d6z]# tar -tf han.tar
hf/
hf/han/
hf/han/hanfeng/
hf/han/hanfeng/66.txt
hf/han/hanfeng/1.txt
hf/han/wu.txt
hf/1.txt
1.txt
4.txt
tar过滤指定的文件,不去打包它们
- tar -cvf han.tar --exclude hanfeng hf/ 1.txt 4.txt 过滤hanfeng文件目录,而后打包hf、1.txt、4.txt文件成han.tar
- --exclude 后面跟过滤到的文件或目录
- 选项 f 后,必须跟tar包的名称
- 重复的打包名称,会直接覆盖掉以前的打包文件
[root@hf-01 d6z]# tar -cvf han.tar --exclude hanfeng hf/ 1.txt 4.txt
hf/
hf/han/
hf/han/wu.txt
hf/1.txt
1.txt
4.txt
- 过滤掉文件、目录和*.txt文件
- 过滤"*.txt"文件必须加""
- --exclude支持过个文件过滤
[root@hf-01 d6z]# tar -cvf han.tar --exclude hanfeng --exclude wu.txt --exclude "*.txt" hf/ 1.txt 4.txt
hf/
hf/han/