- 把文件打包成tar包,但并未被压缩;
[root@Server-n93yom test]# ll total 0 -rw-r--r-- 1 root guanbin 0 Jul 22 16:09 test1 [root@Server-n93yom test]# touch 1.py [root@Server-n93yom test]# touch 2.py [root@Server-n93yom test]# touch 3.py [root@Server-n93yom test]# tar -cvf haha.tar *.py //把当前目录下以.py结尾的文件打包成haha.tar 1.py 2.py 3.py
tar选项说明:1.c为生成档案文件,创建打包文件;2.x为解开档案文件;3.v为列出归档解档的详细过程,显示进度;4.指定档案文件名称,f后面一定是.tar文件,所以必须放选项最后
[root@Server-n93yom tmp]# tar -xvf haha.tar 1.py 2.py 3.py [root@Server-n93yom tmp]# ll total 33808 -rw-r--r-- 1 root root 0 Jul 27 23:18 1.py -rw-r--r-- 1 root root 0 Jul 27 23:18 2.py -rw-r--r-- 1 root root 0 Jul 27 23:18 3.py
- tar命令和gizp命令结合使用,实现文件打包和压缩:tar只负责打包,gzip负责压缩:在linux中最常见的格式为:xxx.tar.gz
[root@Server-n93yom tmp]# tar -zcvf haha.tar.gz *.py 1.py 2.py 3.py [root@Server-n93yom tmp]# ls -lh total 34M -rw-r--r-- 1 root root 0 Jul 27 23:18 1.py -rw-r--r-- 1 root root 0 Jul 27 23:18 2.py -rw-r--r-- 1 root root 0 Jul 27 23:18 3.py -rw-r--r-- 1 root root 10K Jul 27 23:20 haha.tar -rw-r--r-- 1 root root 129 Jul 27 23:36 haha.tar.gz //可以看到haha.tar.gz文件大小只有129字节
- -C为解压缩到指定目录,注意解压缩的目录必须存在)
[root@Server-n93yom tmp]# tar -zxvf haha.tar.gz -C /root/python/ 1.py 2.py 3.py [root@Server-n93yom tmp]# ll -lh /root/python/ total 0 -rw-r--r-- 1 root root 0 Jul 27 23:18 1.py -rw-r--r-- 1 root root 0 Jul 27 23:18 2.py -rw-r--r-- 1 root root 0 Jul 27 23:18 3.py
[root@Server-n93yom ~]# ln -s /var/log/cloudchef/server/cloudchef.log cloudchef.log [root@Server-n93yom ~]# ll total 8 -rw-------. 1 root root 1706 Jun 17 09:56 anaconda-ks.cfg -rw-r--r-- 1 root root 1 Jul 25 23:05 cal.txt lrwxrwxrwx 1 root root 39 Jul 27 23:53 cloudchef.log -> /var/log/cloudchef/server/cloudchef.log drwxr-xr-x 2 root root 42 Jul 27 23:43 python drwxr-xr-x 2 root guanbin 55 Jul 27 23:20 test drwxr-xr-x. 2 root root 145 Jul 27 23:45 tmp