设置 tarfile 内容的文件权限 [英] Setting file permissions on contents of tarfile

查看:43
本文介绍了设置 tarfile 内容的文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在分发之前chmod 777 tarfile 在创建时(或之后不久)的内容?被tar'd 的目录的写权限在tar'ing 时是未知的(但通常为555).我希望展开的目录是全局可写的,而展开 tar 的用户不必在继续之前记住 chmod -R 777 .

Is there a way to chmod 777 the contents of a tarfile upon creation (or shortly thereafter) before distributing? The write permissions of the directory that's being tar'd is unknown at the time of tar'ing (but typically 555). I would like the unrolled dir to be world writable without the users who are unrolling the tar to have to remember to chmod -R 777 <untarred dir> before proceeding.

笨拙的方法是复制目录,然后 chmod -R 777 但我想知道是否有更好的解决方案.

The clumsy way would be to make a copy of the directory, and then chmod -R 777 <copydir> but I was wondering if there was a better solution.

我使用的是 Solaris 10 机器.

I'm on a Solaris 10 machine.

背景:

根目录在我们的 ClearCase vob 中,递归地具有特定的文件权限.一个 tarfile 被创建并分发给我们组织内的多个客户".大多数只需要读取/执行权限(特别是不希望它们可写),但一组特别需要其副本可递归写入,因为他们可以编辑这些文件,甚至恢复到新"副本(即,以我给它们的原始状态).

The root directory is in our ClearCase vob with specific file permissions, recursively. A tarfile is created and distributed to multiple "customers" within our org. Most only need the read/execute permissions (and specifically DON'T want them writable), but one group in particular needs their copy to be recursively writable since they may edit these files, or even restore back to a "fresh" copy (i.e., in their original state as I gave them).

这个小组在技术上有些挑战.即使他们有关于 tarfile 的操作方法"的说明,但他们似乎总是忘记(或出错)将文件设置为在解压缩后可递归写入.这导致我打电话给我诊断各种问题,其根本原因是他们忘记执行(或错误执行)展开目录的 chmod'ing.

This group is somewhat technically challenged. Even though they have instructions on the "how-to's" of the tarfile, they always seem to forget (or get wrong) the setting of the files to be recursively writable once untarred. This leads to phone calls to me to diagnose a variety of problems where the root cause is that they forgot to do (or did incorrectly) the chmod'ing of the unrolled directory.

在你问之前,是的,我给他们写了一个解压/chmod的脚本(专门针对他们),但是......哦,没关系.

And before you ask, yes, I wrote them a script to untar/chmod (specific just for them), but... oh never mind.

所以,我想我会创建一个单独的、可递归写入的 tar 版本来分发给他们.正如我最初所说,我总是可以创建目录的副本,使副本递归可写,然后将副本目录压缩,但目录相当大,磁盘空间有时接近满(可能变化很大),所以复制目录在 100% 的情况下都不可行.

So, I figured I'd create a separate, recursively-writable version of the tar to distribute just to them. As I said originally, I could always create a copy of the dir, make the copy recursively writable and then tar up the copy dir, but the dir is fairly large, and disk space is sometimes near full (it can vary greatly), so making a copy of the dir will not be feasable 100% of the time.

推荐答案

使用 GNU tar,在创建存档时使用 --mode 选项,例如:

With GNU tar, use the --mode option when creating the archive, e.g.:

tar cf archive.tar --mode='a+rwX' *

但请注意,当提取存档时,默认情况下将应用 umask.因此,除非用户的 umask 为 000,否则权限将在此时更新.但是,可以使用 -p (--preserve) 选项忽略 umask,例如:

But note that when the archive is extracted, the umask will be applied by default. So unless the user's umask is 000, then the permissions will be updated at that point. However, the umask can be ignored by using the -p (--preserve) option, e.g.:

tar xfp archive.tar

这篇关于设置 tarfile 内容的文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆