加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 22:38:58 所属栏目:安全 来源:网络整理
导读:如果多次将同一文件添加到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.tarfoofoo~/tmp rm foo~/tmp tar -xf bar.ta
如果多次将同一文件添加到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.

我的理解是,除非使用-k选项,否则-x将始终使用存档中存储的最后一个文件进行覆盖.

编辑:另见GNU documentation for tar.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读