关于tar 的路径问题_20100621
-
gdutllf2006
2010-06-23 13:41:00
-
Linux操作系统
-
原创
关于tar 的路径问题
以绝对路径创建的包:
hpux02[/home/oracle/tmp]$tar -cvf t2.tar /home/oracle/tmp/t1.txt /home/oracle/tmp/t2.txt
则不管你在哪个目录解包,都会还原到原目录
hpux02[/home/oracle/tmp]$tar -xvf t2.tar
x /home/oracle/tmp/t1.txt, 0 bytes, 0 tape blocks
x /home/oracle/tmp/t2.txt, 0 bytes, 0 tape blocks
hpux02[/home/oracle/tmp/td]$tar -xvf ../t2.tar
x /home/oracle/tmp/t1.txt, 0 bytes, 0 tape blocks
x /home/oracle/tmp/t2.txt, 0 bytes, 0 tape blocks
而用相对路径创建的包,则在哪个目录恢复,就恢复到当前目录下.
hpux02[/home/oracle/tmp/td]$tar -cfv test.tar t1.txt t2.txt
hpux02[/home/oracle/tmp/td]$tar -xvf ../t.tar
x ./t1.txt, 0 bytes, 0 tape blocks
x ./t2.txt, 0 bytes, 0 tape blocks
如何恢复到指定目录呢.
1 以绝对目录创建的不可能做到
2 以相对目录创建的则可通过-C
tar -xvf t.tar -C /home/oracle/tmp/td 不行??
3 tar -tvf t.tar 查看有什么文件
4 p 选项 保留之前的权限信息,ownerships
Cause file to be restored to the original modes and
ownerships written on the archive, if possible.
This is the
default for the superuser, and can be overridden
by the o
function modifier. If system protections prevent the
ordinary user from executing chown(), the error is ignored,
and the ownership is set to that of the restoring process
(see chown(2)). The set-user-id, set-group-id, and sticky
bit information are restored as allowed by the protections
defined by chmod() if the chown() operation above succeeds.
测试
ls -l t2.txt
-rw-r--r-- 1 oracle dba 0 Jun 12 17:28 t2.txt
tar -cvf testp.tar t1.txt t2.txt
chmod 777 t2.txt
tar -xvf testp.tar
hpux02[/home/oracle/tmp]$ls -l t2.txt
-rwxrwxrwx 1 oracle dba 0 Jun 12 17:28 t2.txt
没有保留之前的权限信息
hpux02[/home/oracle/tmp]$ls -l t2.txt
-rw-r--r-- 1 oracle dba 0 Jun 12 17:28 t2.txt
保留了之前的权限信息
hpux02[/home/oracle/tmp]$tar -tvf t.tar
rw-r--r-- 108/106 10240 Jun 12 17:28 2010 t1.txt
rw-r--r-- 108/106 0 Jun 12 17:28 2010 t2.txt
rwxr-xr-x 108/106 0 Jun 13 09:01 2010 td/
rw-r--r-- 108/106 0 Jun 12 15:48 2010 td/3.txt
hpux02[/home/oracle/tmp]$cd /home/oracle/tmp/td
hpux02[/home/oracle/tmp/td]$tar -xvfp t.tar td(在归档中找全部以td开头的文件,这样会恢复td/, td/3.txt )
hpux02[/home/oracle/tmp/td]$ls
3.txt td
hpux02[/home/oracle/tmp/td/td]$ls
3.txt
hpux02[/home/oracle/tmp/td]$tar -xvfp t.tar td/ (在归档中找全部以td/开头的文件,但这个是独立的文件,只会恢复一个td/ )