tar与绝对路径

tar命令可以在打包的时候把绝对路径也打包进去,如下:

[root@SI03 tar]# tar cPvf bin.tar /root/tar/bin
/root/tar/bin/
/root/tar/bin/b.out
/root/tar/bin/a.log
/root/tar/bin/c.txt
[root@SI03 tar]# tar tvf bin.tar
drwxr
-xr-x root/root 0 2011-03-09 19:59:09 /root/tar/bin/
-rwxr-xr-x root/root 5069 2011-03-09 17:10:26 /root/tar/bin/b.out
-rwxr-xr-x root/root 0 2011-03-09 19:59:09 /root/tar/bin/a.log
-rwxr-xr-x root/root 0 2011-03-09 19:59:06 /root/tar/bin/c.txt

在Linux下面解压(使用的是GNU的tar),默认情况下,tar会自动把前面的/去掉,然后在当前目录解压:

[root@SI03 a]# tar xvf bin.tar
/root/tar/bin/
tar: Removing leading `
/' from member names
/root/tar/bin/b.out
/root/tar/bin/a.log
/root/tar/bin/c.txt

Unix则不然,会依照绝对路径解压,对路径中的其他文件不影响,对相同的文件,覆盖。如果不存在某个目录,则创建(如果有权限)。

如果要在Unix下面解压包含绝对路径的tar包到某个指定的目录,可以使用pax命令,如下:

[root@SI03 tar]# ls
bin.tar
[root@SI03 tar]# tar tvf bin.tar
drwxr
-xr-x root/root 0 2011-03-09 19:59:09 /root/tar/bin/
-rwxr-xr-x root/root 5069 2011-03-09 17:10:26 /root/tar/bin/b.out
-rwxr-xr-x root/root 0 2011-03-09 19:59:09 /root/tar/bin/a.log
-rwxr-xr-x root/root 0 2011-03-09 19:59:06 /root/tar/bin/c.txt
[root@SI03 tar]# mkdir untar
[root@SI03 tar]# ls
bin.tar untar
[root@SI03 tar]# pax -rpe -f bin.tar -s:^/root/tar/:/root/tar/untar/:g
[root@SI03 tar]# ls
bin.tar untar
[root@SI03 tar]# cd untar/
[root@SI03 untar]# ls
bin
[root@SI03 untar]# cd bin/
[root@SI03 bin]# ls
a.log b.out c.txt
[root@SI03 bin]#

posted on 2011-03-10 11:22  形状奇怪的苹果  阅读(3340)  评论(0编辑  收藏  举报

导航