首页 > 其他 > 详细

tar 使用总结

时间:2014-08-18 17:46:22      阅读:331      评论:0      收藏:0      [点我收藏+]

今天需要备份数据,使用tar命令,总结一下。

压缩命令:

tar -zvvf ticket-data-intgration.tar.gz ticket-data-intgration

压缩但是不包含某个文件夹

tar  --exclude /home/q/ticket-data-intgration/log --exclude /home/q/ticket-data-intgration/cache -zvvf ticket-data-intgration.tar.gz /home/q/ticket-data-intgration

查看tar包的文件

tar -tzvf ticket-data-intgration.tar.gz

错误:/bin/tar: Removing leading `/‘ from member names

首先应该明确:linux系统中,使用tar对文件打包时,一般不建议使用绝对路径。使用绝对路径打包时如果不指定相应的参数,tar会产生一句警告信息:”tar: Removing leading `/’ from member names”,并且实际产生的压缩包会将绝对路径转化为相对路径。比如:

root@queen ~ # tar -czvf robin.tar.gz /home/robin
tar: Removing leading `/ from member names
/home/robin/
/home/robin/file1
/home/robin/file2
/home/robin/file3
root@queen ~ # tar -tzvf robin.tar.gz
drwxr-xr-x robin/root        0 2009-11-10 18:51:31 home/robin/
-rw-r--r-- robin/root        0 2009-11-10 18:51:28 home/robin/file1
-rw-r--r-- robin/root        0 2009-11-10 18:51:30 home/robin/file2
-rw-r--r-- robin/root        0 2009-11-10 18:51:31 home/robin/file3
root@queen ~ #

这样的一个压缩包,如果我们再去解开,就会当前目录(也即此例中的“~”)下再新建出“./home/robin/” 两级目录。对于这样的压缩包,解压方法是使用参数 “-C”指解压的目录为根目录(“/”):tar -xzvf robin.tar.gz -C /

更为方便的方法是在打包和解开的时候都使用参数 -P

root@queen ~ # tar -czvPf robin.tar.gz /home/robin/
/home/robin/
/home/robin/file1
/home/robin/file2
/home/robin/file3
root@queen ~ # tar tzvf robin.tar.gz
drwxr-xr-x robin/root        0 2009-11-10 18:51:31 /home/robin/
-rw-r--r-- robin/root        0 2009-11-10 18:51:28 /home/robin/file1
-rw-r--r-- robin/root        0 2009-11-10 18:51:30 /home/robin/file2
-rw-r--r-- robin/root        0 2009-11-10 18:51:31 /home/robin/file3
root@queen ~ # tar -xzvPf robin.tar.gz
/home/robin/
/home/robin/file1
/home/robin/file2
/home/robin/file3
root@queen ~ #

注意:上面-P的大小写和位置都不能改变

tar 使用总结,布布扣,bubuko.com

tar 使用总结

原文:http://www.cnblogs.com/liqiu/p/3919749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!