[英]Permission with tar command
I have some problem with linux "tar" command.I want to unzip a config001.gz to a directory(with owner root ,group root and 777 permission as show in pic). 我对linux“ tar”命令有一些问题。我想将config001.gz解压缩到目录(如图所示,所有者为root,组为root,权限为777)。
My origin dir and target dir is shown in pic. 我的原点目录和目标目录如图所示。
My question is: 我的问题是:
my mount infomation: fuse.mfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0 我的安装信息:fuse.mfs rw,nosuid,nodev,relatime,user_id = 0,group_id = 0,allow_other 0 0
why there is en empty folder in a config001.tgz file? 为什么config001.tgz文件中有一个空文件夹?
There is the "root folder" included in the tar archive. tar存档中包含“根文件夹”。 The folder the tar was in. The privileges, owner and group, permissions and creation/modification (or one of them, I am not sure) dates are included. tar所在的文件夹。其中包括特权,所有者和组,权限以及创建/修改(或者,我不确定其中之一)的日期。 You can create such archive with: 您可以使用以下方式创建此类归档文件:
mkdir -p /tmp/a
cd /tmp/a
echo 123 > 1
echo 234 > 2
tar cfvp /tmp/test.tar .
# and inspect with:
tar -tvf ./test.tar
drwxr-xr-x kamil/kamil 0 2019-07-15 12:50 ./
-rw-r--r-- kamil/kamil 4 2019-07-15 12:50 ./2
-rw-r--r-- kamil/kamil 4 2019-07-15 12:50 ./1
By specifing the .
通过指定.
, ie. ,即。 the current directory, the information about the current directory itself will be included in he tar
. 当前目录中,有关当前目录本身的信息将包含在tar
。 Ie. IE浏览器。 the information about the owner and group, permissions and dates. 有关所有者和组,权限和日期的信息。
if I don't append --no-overwrite-dir after command,it will raise error, what permission does "tar" want to change? 如果我在命令后不附加--no-overwrite-dir,则会引发错误,“ tar”要更改什么权限?
tar
wants to change the permissions of the directory you are inside. tar
想要更改您所在目录的权限。 The hpc_dir
directory. hpc_dir
目录。 The hpc_dir
is owned by root
, so tar
can't change/touch it. hpc_dir
由root
拥有,因此tar
无法更改/触摸它。
why --no-overwrite-dir option can fix the problem? 为什么--no-overwrite-dir选项可以解决此问题?
Because then tar
sees the the currect directory hpc_dir
exists. 因为然后tar
看到当前目录hpc_dir
存在。 Because of that, tar
doesn't try to create the directory, nor tries to change the owner and group permissions of the directory, nor tries to restore the creation date of the directory. 因此, tar
不会尝试创建目录,也不会尝试更改目录的所有者和组权限,也不会尝试恢复目录的创建日期。
You could just go with mkdir somedir; tar xzfv archive.tar -C somedir
您可以只使用mkdir somedir; tar xzfv archive.tar -C somedir
mkdir somedir; tar xzfv archive.tar -C somedir
- that way the somedir
will be created by current user, so tar
will be able to change it's properties. mkdir somedir; tar xzfv archive.tar -C somedir
这样, somedir
将由当前用户创建,因此tar
将能够更改其属性。
Or you could just change the owner of hpc_dir
directory, letting your user modify it. 或者,您可以只更改hpc_dir
目录的所有者,让用户对其进行修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.