首页 > 解决方案 > 如何将多个 tar 文件合并为一个 tar 文件

问题描述

根据 gnu 文档,要将一个或多个档案添加到另一个档案的末尾,我可以使用“--concatenate”操作。

但是在我的测试中,我发现我一次不能添加多个文件。

# ls -al
total 724
drwxr-xr-x.  3 root root     60 Oct 14 17:40 .
dr-xr-xr-x. 32 root root   4096 Oct 14 16:28 ..
-rw-r--r--.  1 root root 245760 Oct 14 18:07 1.tar
-rw-r--r--.  1 root root 245760 Oct 14 18:07 2.tar
-rw-r--r--.  1 root root 245760 Oct 14 18:07 3.tar
# tar tvf 1.tar
-rw-r--r-- root/root    238525 2021-10-14 17:28 1.txt
# tar tvf 2.tar
-rw-r--r-- root/root    238525 2021-10-14 17:29 2.txt
# tar tvf 3.tar
-rw-r--r-- root/root    238525 2021-10-14 17:29 3.txt

看来它只拾取了第一个参数而忽略了其余的

# tar -A -f 1.tar 2.tar 3.tar
# tar tvf 1.tar
-rw-r--r-- root/root    238525 2021-10-14 17:28 1.txt
-rw-r--r-- root/root    238525 2021-10-14 17:29 2.txt

标签: linuxtar

解决方案


如出色而全面的超级用户回答中所述,

这是 gnu tar 中的一个已知错误(2008 年 8 月报告)


推荐阅读