日期:2014-05-16  浏览次数:20755 次

tar的-p参数
tar的-p参数到底是什么含义:

在man中,解释如下:extract all protection information 提取所有受保护的信息。

问题1:那么,什么叫受保护的信息呢?

在info中,解释如下:
`--preserve-permissions'
`--same-permissions'
`-p'
  When `tar' is extracting an archive, it normally subtracts the
  users' umask from the permissions specified in the archive and uses
  that number as the permissions to create the destination file.
  Specifying this option instructs `tar' that it should use the
  permissions directly from the archive. *Note Writing::.
也就是说,加了-p之后,tar进行解压后,生成的文件的权限,是直接取自tar包里面文件的权限,那么不加-p参数,将还要再减去umask的值

但是我测试了下,结果视乎不是这样的:
==========各属性权限如下:
root@DaLinux liuda]# ll
total 76
-rw-r--r-- 1 root root 3 Oct 11 02:44 1
-rwxrwxrwx 1 root root 11 Oct 12 02:15 10
-rw-r--r-- 1 root root 3 Oct 12 12:45 11
-rw-r--r-- 1 root root 5 Oct 12 12:53 12
-rw-r--r-- 1 root root 2 Oct 11 02:45 2
-rw-r--r-- 1 root root 2 Oct 11 02:45 3
-rw-r--r-- 1 root root 2 Oct 11 02:45 4
-rw-r--r-- 1 root root 2 Oct 11 02:45 5
-rwxrwxrwx 1 root root 2 Oct 11 02:51 6
-rwxrwxrwx 1 root root 2 Oct 12 12:54 7
-rwxrwxrwx 1 root root 2 Oct 12 12:48 8
-rwxrwxrwx 1 root root 4635 Oct 11 03:23 9
drwxr-xr-x 2 root root 4096 Oct 12 02:18 liuda
-rw-r--r-- 1 root root 4617 Oct 12 12:06 man.config
-rw-r--r-- 1 root root 2049 Oct 12 12:06 man.config.bz2
-rw-r--r-- 1 root root 2049 Oct 12 12:06 man.config.bz2-3
-rw-r--r-- 1 root root 79 Sep 19 02:51 sed

==========这是进行压缩:
root@DaLinux liuda]# tar -jcv -f ../ccc/test.tar.bz2 .
./
./6
./7
./sed
./11
./9
./liuda/
./liuda/77
./3
./2
./4
./1
./man.config.bz2
./8
./5
./man.config
./man.config.bz2-3
./12
./10

=================这是进行解压
[root@DaLinux ccc]# tar -xv -f test.tar.bz2 -C ccc/
./
./6
./7
./sed
./11
./9
./liuda/
./liuda/77
./3
./2
./4
./1
./man.config.bz2
./8
./5
./man.config
./man.config.bz2-3
./12
./10

===========这是查看解压后生成的文件的权限
[root@DaLinux ccc]# ll
total 76
-rw-r--r-- 1 root root 3 Oct 11 02:44 1
-rwxrwxrwx 1 root root 11 Oct 12 02:15 10
-rw-r--r-- 1 root root 3 Oct 12 12:45 11
-rw-r--r-- 1 root root 5 Oct 12 12:53 12
-rw-r--r-- 1 root root 2 Oct 11 02:45 2
-rw-r--r-- 1 root root 2 Oct 11 02:45 3
-rw-r--r-- 1 root root 2 Oct 11 02:45 4
-rw-r--r-- 1 root root 2 Oct 11 02:45 5
-rwxrwxrwx 1 root root 2 Oct 11 02:51 6
-rwxrwxrwx 1 root root 2 Oct 12 12:54 7
-rwxrwxrwx 1 root root 2 Oct 12 12:48 8
-rwxrwxrwx 1 root root 4635 Oct 11 03:23 9
drwxr-xr-x 2 root root 4096 Oct 12 02:18 liuda
-rw-r--r-- 1 root root 4617 Oct 12 12:06 man.config
-rw-r--r-- 1 root root 2049 Oct 12 12:06 man.config.bz2
-rw-r--r-- 1 root root 2049 Oct 12 12:06 man.config.bz2-3
-rw-r--r-- 1 root root 79 Sep 19 02:51 sed

从压缩到解压,都没有使用过-p的参数,但是我最后得到的权限依然和原始文件的权限是一致的,并没有减掉什么umask值,这是怎么回事?

问题2:tar的-p参数加与不加,到底有什么区别?-p参数具体的含义,到底是什么?

------解决方案--------------------
因为你是以root用户操作的,换成是普通用户就会有变化的。