8

I'm using gnu tar with a few instances of --exclude specified.

I get both the

Removing leading / from member names

and

Removing leading / from hard link targets

warnings. What's the difference between them?

1 Answer 1

10

No entry within a tarball may begin with a "/", i.e. have an absolute path. It's a security feature, so that if you unpack the tarball, you can be sure that all files will reside in the target directory and subdirectories, instead of being scattered all over the system (and possibly overwriting critical files).

The warnings you see result from tar stripping the leading "/" from any absolute paths, both for normal files ("member names") and hard links ("hard link targets").

For example, this command...

/home/user $ tar czf tarball.tgz /home/user/data

...would result in those warnings, as "/home/..." is converted into "home/...". Unpacking the tarball...

/home/user $ tar xzf tarball.tgz

...would result in all files being unpacked to /home/user/home/user/data. If tar hadn't stripped the leading slashes, the files in /home/user/data would have been overwritten instead.

4
  • 4
    tar archives are allowed to have absolute names, the stripping can be disabled with -P if necessary... It should probably also be noted that tar archives store hard links in a similar manner to symlinks -- the second and further links actually point to the first by its path (not by inode), which is why the second message is displayed. Jun 4, 2012 at 14:17
  • @grawity: Uhhhh... let's say it's possible to disable the stripping. It's about as "allowable" as unpacking thousands of files in the current directory. ;-)
    – DevSolar
    Jun 4, 2012 at 14:26
  • I understood the reason for stripping the slash, why it's the default, etc, but didn't know that the key difference in the two warnings was "normal files" vs "hard links". Thanks (and to grawity too). Jun 4, 2012 at 14:39
  • I ran into it when I specified 2 dirs starting with /. It somehow gives the second message in such a case, e.g. tar czf a.tar.gz /a/a /a/b. And it doesn't seem to be about hard links. At least not in my case. Maybe it tries to circumvent some issue with hard links, but doesn't care to distinguish hard links for non-hard links.
    – x-yuri
    Dec 20, 2021 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .