linux - append 到 tar 存档会删除其他所有内容

标签 linux append tar

为什么 append 一个 tar 存档会删除其他所有内容?

[jalal@adelie-07] (23)$ tar zcvf tar_new.tar.gz new_file 
new_file
[jalal@adelie-07] (24)$ tar -tvf tar_new.tar.gz 
-rw-rw-r-- jalal/jalal       0 2016-02-03 00:20 new_file

基本上,如何在不删除所有其他内容的情况下将单个文件添加到 tar 文件?

最佳答案

您不能在压缩的 tar 文件中追加新文件。我们可以使用选项“-r”而不是“-c”将文件添加到现有的简单 tar 文件。

$ ls
a  b
$ tar -cvf tar_new.tar a b
a
b
$ tar -tvf tar_new.tar 
-rw-rw-r-- guest/guest 0 2016-02-03 12:17 a
-rw-rw-r-- guest/guest 0 2016-02-03 12:17 b
$ touch newfile
$ tar -rvf tar_new.tar newfile 
newfile
$ tar -tvf tar_new.tar 
-rw-rw-r-- guest/guest 0 2016-02-03 12:17 a
-rw-rw-r-- guest/guest 0 2016-02-03 12:17 b
-rw-rw-r-- guest/guest 0 2016-02-03 12:18 newfile
$ gzip tar_new.tar 
$ ls
a  b  newfile  tar_new.tar.gz
$ 

关于linux - append 到 tar 存档会删除其他所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35169954/

相关文章:

c++ - 将 UTC tm* 转换为本地化 tm* 的跨平台方式?

ios - 快速推送/append 数组

linux - 创建 .tar.gz 文件时的目录包括主文件夹和公共(public) html 文件夹

http - 创建要通过 Google App Engine 提供的 tar 文件

linux - 安装 gigablast。使文件不工作

android - 使用批处理文件在 linux shell 中运行命令

linux - 为什么 Windows VM 会产生与 Linux 不同的浮点输出?

c++ - 以追加模式打开文件以用 C++ 写入是否会为整个文件分配内存?

jQuery:如何 append $(this)

php - tar文件保留完整路径。如何停止呢?