码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 之 tar打包压缩与解压使用

时间:2018-05-07 21:43:44      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:tar

tar打包压缩与解压使用
1.tar 压缩打包/root/Desktop整个目录,并把打包的文件放到/root/backup目录下
[root@localhost ~]# tar -czvf /root/backup/desktop.tar.gz Desktop/
Desktop/
Desktop/abc/
Desktop/abc/tff.txt
Desktop/abc/1.txt
Desktop/abc/abc.log
Desktop/def/
Desktop/def/222.txt
Desktop/def/333.txt
Desktop/def/111.txt

2.tar 压缩打包/root/Desktop整个目录,并排除def目录
root@localhost ~]# tar -czvf /root/backup/desktop2.tar.gz Desktop/ exclude=Desktop/def             #Desktop/def 不能写成Desktop/def/
Desktop/
Desktop/abc/
Desktop/abc/tff.txt
Desktop/abc/1.txt
Desktop/abc/abc.log

3.tar压缩打包/root/Desktop整个目录,并排除打包所有txt文件
[root@localhost ~]# tar -czvf /root/backup/desktop3.tar.gz Desktop/ --exclude=*.txt
Desktop/
Desktop/abc/
Desktop/abc/abc.log
Desktop/def/

4.tar 解压到指定目录,如把/root/backup/desktop2.tar.gz 解压到/root/kang 目录下
[root@localhost backup]# tar -zxvf desktop2.tar.gz -C /root/kang/
Desktop/
Desktop/abc/
Desktop/abc/tff.txt
Desktop/abc/1.txt
Desktop/abc/abc.log
[root@localhost backup]# cd /root/kang/
[root@localhost kang]# ll
total 24
drwxr-xr-x 3 root root 4096 May  7 20:58 Desktop
-rw-r--r-- 1 root root    0 May  6 21:21 d.txt
drwxr-xr-x 2 root root 4096 May  6 21:14 kang
-rw-r--r-- 1 root root    0 May  5 18:55 kang.txt
drwxr-xr-x 2 root root 4096 May  5 23:40 nginx
-rw-r--r-- 1 root root  111 May  7 13:41 nginx.conf
-rw-r--r-- 1 root root    5 May  5 23:40 test.sh
-rw-r--r-- 1 root root   38 May  5 23:27 test.txt

5.查看压缩包里的内容
[root@localhost backup]# tar tf desktop2.tar.gz 
Desktop/
Desktop/abc/
Desktop/abc/tff.txt
Desktop/abc/1.txt
Desktop/abc/abc.log

Linux 之 tar打包压缩与解压使用

标签:tar

原文地址:http://blog.51cto.com/12965094/2113753

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!