help-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-tar] Using --directory and --no-recursion


From: Jakob Bohm
Subject: Re: [Help-tar] Using --directory and --no-recursion
Date: Mon, 11 Feb 2019 18:07:49 +0100
User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 10/02/2019 19:10, Sergey Poznyakoff wrote:
Hi Brian,

The *--directory* option seem to be ignored, e.g.:

tar --directory="/tmp/fld 1/" --create --file="/tmp/fld 1/files.tar"
--exclude="files.tar" --no-recursion .
In fact, it is not. You have instructed tar to:

  1) Change to the directory "/tmp/fld 1/"
  2) Create archive "/tmp/fld 1/files.tar"
  3) Add to that archive the directory "." *without recursing into it*.
That's exactly what you get: an archive with a single "." member in it.
The --directory option is a no-op here, because any directory has the
"." entry and archiving only that entry makes little sense anyway.
Notice also, that the --exclude option is entirely irrelevant here,
since the command explicitly states that no other entries, except "."
should appear in the created archive.
I’m trying to create an archive without full-path information and no
recursion.
In other words, you wish to put into the archive all files under
"/tmp/fld 1/", stripping their directory information, so that, e.g.
files "/tmp/fld 1/foo/bar" and "/tmp/fld 1/foo/baz/bar" will be stored
in the archive as two distinct members with the same name: "bar". Do I
get it right?

And one could also argue that using --file="files.tar" would save the
archive in the folder specified in the --directory option,
Not at all. The "-C" option affects arguments that supply or modify
files to be added to the archive. The --file option does not add any,
it merely specifies the archive name. The subsection 3.4.4
"Position-Sensitive Options" in GNU tar manual contains the exhaustive
list of affected options.

If I try:

tar --directory="/tmp/fld 1/" --create --file="/tmp/fld 1/files.tar"
--exclude="files.tar" --no-recursion "/tmp/fld 1/”*
This command instructs tar to

  1) Change to the directory "/tmp/fld 1/"
  2) Create archive "/tmp/fld 1/files.tar"
  3) Add to that archive any files and directories beginning with
     "/tmp/fld 1/*", but without recursing further into any directoris.

In this case, the --directory option is a no-op again -- this time
because you supply the full path prefix of the files to be archived.
The --exclude has no effect because no file will start with "file.tar":
as all files start with "/tmp/fld 1/". If you intend to exclude
"/tmp/fld 1/files.tar" you should use '--exclude "/tmp/fld 1/files.tar"',
but that's superfluous, as the archive itself will never be archived
anyway.
I don't think that would work because the * is expanded by the shell,
not by tar, and the shell doesn't interpret tar's options.

If so, I guess the only solution is this:

  (cd "/tmp/fld 1" && /bin/tar --create --file="files.tar" \
    --exclude="files.tar" --no-recursion .* *)

Where the shell executes the cd command before expanding .* and *
into file names without paths.

My proposed command uses "/bin/tar" in case someone has added "."
to the PATH variable.

Enjoy

Jakob
--
Jakob Bohm, CIO, Partner, WiseMo A/S.  https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded




reply via email to

[Prev in Thread] Current Thread [Next in Thread]