如何將 tar 檔案及其內容的擁有者設定為目前用戶

如何將 tar 檔案及其內容的擁有者設定為目前用戶

我需要將 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.

相關內容