![如何将 tar 文件及其内容的所有者设置为当前用户](https://linux22.com/image/109368/%E5%A6%82%E4%BD%95%E5%B0%86%20tar%20%E6%96%87%E4%BB%B6%E5%8F%8A%E5%85%B6%E5%86%85%E5%AE%B9%E7%9A%84%E6%89%80%E6%9C%89%E8%80%85%E8%AE%BE%E7%BD%AE%E4%B8%BA%E5%BD%93%E5%89%8D%E7%94%A8%E6%88%B7.png)
我需要将 tar 文件的所有者及其内容设置为当前用户。
我将在文件夹中接收来自用户 FOO 的文件config_files/billing/xml/incommingBills 每当 tar 文件复制到此位置时,我想将所有者设置为当前用户,即 BAR。还希望将 tar 文件的内容设置为 BAR。
答案1
如果您要处理tar
文件本身,则文件所有者或 root 用户必须chown newusername /path/to/file
.或者,如果您具有超级用户访问权限,则可以sudo chown $(whoami) /path/to/file
。
如果您谈论的是包含的所有权信息之内该tar
文件,我将遵循手册:
-o (x mode) Use the user and group of the user running the program rather than those specified in the archive. Note that this has no significance unless -p is specified, and the program is being run by the root user. In this case,
the file modes and flags from the archive will be restored, but ACLs or owner information in the archive will be discarded.