How to have tar follow all symlinks except one recursive symlink
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
.
Related videos on Youtube
James Mitchell
Updated on September 18, 2022Comments
-
James Mitchell almost 2 years
Is there a way (in several commands if necessary) to make a
tar
archive that follows all the symlinks (like withtar -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 likeproject2
andproject3
, but I do not want it to follow the recursive symlink it has to itself because it's not necessary and it causestar
to run forever.From the
man
page it looks like I can do this withtar -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.