Quote:> I have problem when I try gzipping and untarring a file.
> When I do that tar will unzip the files in de directory that it originally
> By doing this I sometimes e*ntly overwrite somefiles. This is very
> What I would like to do in put the file in a specific directory.
> I have viewed the man pages of tar and could not find a signal way to
> accomplish that.
> This is the command I use;
> gzip -dc filename.tar.gz | tar xvof -
> This will try to unzip the file in :
> what I want to do is put the file in directory /temporary instead of
Well, a few points, "Best Practices", etc.
It's generally advisable to inspect the contents (at least pathnames) of
the contents of a tar archive before extracting the contents. This
is critical if contents haven't been verified and/or if an ID of any
privilege is used to extract the tar archive.
The tar program restores items to the pathnames stored in the archive.
Best Practice is to always use relative pathnames (pathnames not
starting with /) when creating tar archives. Similarly, it's also Best
Practice to never use .. directory in creating a tar archive. If tar
archive was created with relative pathnames, having the current working
directory of tar be a suitable directory when extracting from the tar
archive, is usually sufficient to avoid placing extracted contents
anywhere particularly unexpected or dangerous (presuming one has
reviewed the pathnames stored in the archive). E.g.:
$ gzip -d < foo.tar.gz | (cd /temporary && tar -xf -)
If the tar archive contains absolute pathnames (pathnames starting with
/) some versions of tar (e.g. GNU tar) can suppress the absolute
If one needs to restore from tar archive that contains
absolute pathnames, and one doesn't have access to a version of tar that
can be used to suppress absolute pathnames, but one does have superuser
access available, chroot can be used to restore relative to a
chroot root, rather than the actual system root. Note however that such
an approach can be potentially non-trivial, as all the requisite
components necessary to do the restore need to be present in the chroot
environment. This might still be problematic if there are
conflicts between absolute pathnames in the archive and requisite
components necessary to do the restore.