Tar – Unpacking Tarball with Hard Links on File System Without Hard Links

afshard linktar

I got a tarball (let's say t.tar.gz) that contains the following files

./a/a.txt
./b/b.txt 

where ./b/b.txt is a hard link to ./a/a.txt.

I want to unpack the tarball on a network file system (AFS) that only supports hard links in the same directory (see here).
Therefore, just unpacking it via tar -xzf t.tar.gz raises an error that the hard link ./b/b.txt cannot be created.

So far, my solution to the problem was to unpack ./t.tar.gz on a file system that supports ordinary hard links. Then pack it again with the option --hard-dereference as the GNU tar manual proposes. And lastly, unpack that new tarball into the AFS.

As this is unsatisfactory for me, I'm asking if there is an easier way to get the content of the archive unpacked directly to it's final destination? Such as an equivalent option to --hard-dereference for unpacking instead of archiving?

Best Answer

Mount the archive as a directory, for example with AVFS, then use your favorite file copying tool.

mountavfs
cp -a --no-preserve=links ~/.avfs/path/to/t.tar.gz\# target-directory/

or

mountavfs
rsync -a ~/.avfs/path/to/t.tar.gz\#/ target-directory/
Related Question