|
--numeric-owner
This option will notify 'tar' thar it should use numeric user and group IDs when creating a 'tar' file, rather than names.
This option allows (ANSI) archives to be written without user/group name information or such information to be ignored when extracting. It effectively disables the generation and/or use of user/group name information. This option forces extraction using the numeric ids from the archive, ignoring the names.
This if useful in certain circumstances, when restoring a backup from an emergency floppy with different passwd/group files for example. It is otherwise impossible to extract files with the right ownerships if the password file in use during the extraction does not match the one belonging to the file system(s) being extracted. This occurs, for example, if you are restoring your files after a major crash and had booted from an emergency floppy with no password file or put your disk into another machine to do the restore.
此选项会通知 “tar” 命令,在创建 “tar” 文件时应使用数字形式的用户和组 ID,而非名称。
该选项使得(ANSI)归档文件在写入时可不包含用户 / 组名称信息,或者在提取时忽略此类信息。实际上,它禁用了用户 / 组名称信息的生成及使用。此选项强制在提取时使用归档文件中的数字 ID,而忽略名称。
在某些特定情况下,此功能很有用。例如,从应急软盘恢复备份时,若应急软盘上的密码文件(passwd)/ 组文件(group)与原系统不同,就会用到该功能。如果提取过程中使用的密码文件与被提取文件系统对应的密码文件不匹配,那么要以正确的所有权提取文件是不可能的。比如,在系统严重崩溃后恢复文件,且是从没有密码文件的应急软盘启动,或者将磁盘放入另一台机器进行恢复操作时,就会出现这种情况。
举一个使用数字形式的用户和组ID的具体例子。假设你有一个系统,其中有两个用户:
用户 1:用户名 alice,用户 ID(UID)是 1001,所属主要组是 users,组 ID(GID)是 100。
用户 2:用户名 bob,用户 ID(UID)是 1002,所属主要组也是 users,组 ID(GID)同样是 100。
现在,你要创建一个 tar 归档文件,并且希望使用数字形式的用户和组 ID ,而不是用户名和组名。在使用 tar 命令时,你可以添加相应的选项(如 --numeric-owner ,不同系统可能略有差异)。
例如,你要归档 alice 用户家目录下的 documents 文件夹:
tar --numeric-owner -cvf alice_docs.tar /home/alice/documents
在这个归档文件 alice_docs.tar 中,文件的所有者信息将以数字 1001 (UID)和 100 (GID)记录,而不是用户名 alice 和组名 users。
当你在另一个系统上提取这个归档文件时,如果该系统没有 alice 这个用户名,但有用户 ID 为 1001 的用户,以及组 ID 为 100 的组,那么文件提取后的所有者和组将正确对应到该系统上 ID 匹配的用户和组,而不会因为用户名或组名不匹配而出现权限问题。例如,在新系统上提取文件:
tar -xvf alice_docs.tar
提取后的文件所有者将是 ID 为 1001 的用户,组为 ID 为 100 的组,即使新系统中这些 ID 对应的用户名和组名与原系统不同。
|
|