在不创建新目录的情况下解压缩 tar,仅将 tar 中的新文件合并到现有目录结构中

Unpack a tar without creation of new directories, only merge new files from tar into existing directory structure

情况:

让我们提到有一个 tar 文件,其结构如下:

在我的 磁盘 上有一个结构如下的目录:

问题:

有没有办法实现解压命令不创建新目录(= 解压位置不存在的目录应 skipped/excluded)并且已经存在的文件不会被替换?

解压后磁盘结构应该是这样的:

(请注意不要创建DIR C)

更新

我已经发现'--skip-old-files'实现了 old/existing 文件在解包时不会被替换。

for d in $(ls -d /home/bob/*/); do tar -x -k -f /tmp/test.tar  ${d}/* ; done

其中 $(ls -d /home/bob/*/) 仅列出目标目录,-k 保留现有文件