如果多次将同一个文件添加到一个 tar 文件中,然后提取该文件,是否保证提取的版本与上次添加的版本相同?
~/tmp> echo hi > foo
~/tmp> tar -cf bar.tar foo
~/tmp> echo bye > foo
~/tmp> tar -uf bar.tar foo
~/tmp> tar -tf bar.tar
foo
foo
~/tmp> rm foo
~/tmp> tar -xf bar.tar foo
~/tmp> cat foo
bye
这是有道理的,但我找不到任何相关的文档。我想知道是否有知情人士可能知道,或者是否有人知道情况并非如此?
最佳答案
Some documentation for tar是这样说的:
When you extract a file from the archive, only the version stored last will wind up in the file system. Because '--extract' ('-x') extracts files from an archive in sequence, and overwrites files with the same name in the file system, if a file name appears more than once in an archive the last version of the file will overwrite the previous versions which have just been extracted. You should avoid storing older versions of a file later in the archive.
我的理解是,除非您使用 --keep-old-files
选项,否则 -x
将始终覆盖存档中存储的最后一个文件。
编辑:另见 GNU documentation for tar
.
关于bash - 从具有重复条目名称的 tar 文件中提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376066/