1

Is there a way (in several commands if necessary) to make a tar archive that follows all the symlinks (like with tar -h) except for one recursive symlink, which should be preserved as it is?

I have a directory structure like this:

project1
  code folder
  dependencies folder
    symlink to project1 folder (recursive!)
    symlink to project2 folder
    symlink to project3 folder
    ... more symlinks, folders, etc
project2
  code folder
project3
  code folder
... more projects

I want to tar project1 and have it follow all the symlinks to copy external folders like project2 and project3, but I do not want it to follow the recursive symlink it has to itself because it's not necessary and it causes tar to run forever.

From the man page it looks like I can do this with tar -H but I will have to specify every symlink I want to follow. That is a long list and requires updating any time I add another symlinked dependency, so I am looking for a solution that works with less maintenance.

The quick answer here is "don't use recursive symlinks" and that is what I am doing for now, but it is something I would like to have for my project and I can't do it without coming up with a solution to this problem.

1

Make the archive, with -h, but excluding the specific problem link with --exclude=path/to/naughty/symlink.

Then, add the problem child with tar --append without -h.

Do not use a compression option (e. g. tar j or tar z) as a compressed tarball is incompatible with "postprocessing" such as --append and --delete. Once you're done appending files, you can then gzip tarball.tar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.