How do I tar ball/compress a directory hierarchy with soft links in Linux?
3 Answers
GNU tar normally includes symlinks in the tarball it generates. If you want it to include the file the symlink points to instead then pass it -h
/--dereference
when creating the tarball.
When used with standard arguments tar xvf
,
the soft links are saved in the tar archive as soft-links.
Then there are two cases:
- If your symlink is a full pathname, it might be broken when untarred.
- If your symlink is a relative pathname, under the folder you are tarring, it will work fine when extracted.
If you want to tar the file and not the symlink, you can use the -h / --dereference
arguments.
-
1And how is that different from another answer, which as well doesn't work?– EugZolSep 21, 2021 at 14:14
-
1@EugZol It works but you need to add
h
beforef
. Sotar -hxvf
for instance. Oct 22, 2021 at 10:25 -
8
Just another way, using /etc as an example:
find /etc | cpio -puvdm . ; tar czf ttt.tgz etc
rm -rf etc
tar xvzf ttt.tgz
ls -l etc/rc*
-
1Welcome to Super User! Before answering an old question having other answers ensure your answer adds something new or is otherwise helpful in relation to them. Here is a guide on How to Answer. There is also a site tour and a help center. May 30, 2023 at 16:05
-
1Please note the conventions for formatting How do I format my posts using Markdown or HTML. May 30, 2023 at 16:05