why does tar archive directory differently based on command line?

Lowell Gilbert freebsd-questions-local at be-well.ilk.org
Sun Feb 8 17:57:27 UTC 2015


Manish Jain <bourne.identity at hotmail.com> writes:

> I am having problems trying to understand why does tar archive
> differently with the following 2 commands, presuming xyz is a
> sub-directory :
>
> tar -c -f - ./xyz | gzip > xyz.tar.gz//xyz nested one level under . and ..
> tar -c -f - xyz   | gzip > xyz.tar.gz//no . or ..
>
> With the first invocation, I get a top-level nesting that just has . and ..
> With the second, I get a top-level nesting that has xyz, which is much
> preferable

Right. tar(1) stores the path to the file. This is essential
functionality, so if you want a particular path stored, you
provide that path in the way you invoke tar in the first place.

> The first invocation leads to an absurdity that you have to cd into
> . (sounds recursively impossible) to actually get to xyz

It's neither absurd nor recursively impossible (whatever that
means). If you were planning to extract the tar file from one
level higher up the destination tree, it would be exactly what
you would want.

Perhaps you would be happier with a GUI application for
creating your tar files. There are many fine choices, and you
probably have one (or more) already installed on your system.


More information about the freebsd-questions mailing list