4

If I have a tar file, bob.tar, which contains real_file and link_to_real_file, in which the latter is a symlink, is there a way to extract the contents of bob.tar so that link_to_real_file will not be a symlink, but be a copy of real_file.

I know this is indeed possible on the creation side, if I use the -h flag.

The command tar -cvhf bob.tar real_file link_to_real_file will dereference link_to_real_file, but I want to do this on the extraction side regardless of how the tar file was created.

Chance
  • 251
  • 1
  • 3
  • 10

2 Answers2

2

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

mountavfs
cp -RLp ~/.avfs$PWD/bob.tar\# target-directory/
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • A serious caveat to this is if you are attempting to solve this problem when running inside a containerized build system, where mountavfs is not an option as the fuse kernel module is not loaded. We need an answer that covers this. – Routhinator Mar 30 '23 at 18:27
-2

Here you go

  1. Extract the archive
  2. Recreate the archive using -h
  3. Extract again
roaima
  • 107,089
  • 14
  • 139
  • 261