bash - 从具有重复条目名称的 tar 文件中提取

标签 bash tar

如果多次将同一个文件添加到一个 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/

相关文章:

macos - 获取文件信息中的 "Where from"值

git - 如何在不修改 .git/index 的情况下运行 git status - 例如在 PROMPT_COMMAND 中

Java:验证 TAR 文件

java- 从文件中提取/压缩文件的库

linux - nfs mount shell 脚本中需要一元运算符

Linux bash 脚本卡在 sleep 状态

bash - 用新行拆分很长(4GB)的字符串

bash - 如何将 Pigz 与 Tar 一起使用

tar 预运行以评估预期的文件大小或数量

tar -cf 不保留确切的修改时间