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: Sergey Poznyakoff
Subject: Re: [Help-tar] Using --directory and --no-recursion
Date: Sun, 10 Feb 2019 20:10:25 +0200

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.

Best regards,
Sergey



reply via email to

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