bug-tar
[Top][All Lists]
Advanced

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

Re: [Bug-tar] Bug with --no-recursion and . or simply user error?


From: Helmut Waitzmann
Subject: Re: [Bug-tar] Bug with --no-recursion and . or simply user error?
Date: Sat, 12 Jan 2008 11:16:10 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

"deanna dunker" <address@hidden> writes:

>I'll first explain three commands that work as expected, then I'll
>provide fourth that doesn't quite do what I expect it to do. I've been
>banging my head against this for over a full workday and could use
>fresh sets of eyes.I tried this mostly on GNU tar version 1.17 but
>found the same results in 1.14 from another machine I had tested on.
>
>1. When I perform a tar -cf somefile.tar . it tars the current
>directory I'm in, including hidden files & directories.  (expected
>behavior)

It stores the current directory and (recursively) all files and
subdirectories that are located in it or in a subdirectory of it,
i.e. the whole file tree rooted at the current directory is stored.

>2. When I perform a  tar -cf somefile.tar * it tars the current
>directory I'm in, excluding hidden files & directories. (expected
>behavior)

Not exactly:  It recursively stores all non-hidden directories and all
non-hidden non-directories, lying in the current directory, but not the
current directory itself, in the archive.

>3. When I perform a tar -cf somefile.tar --no-recursion *, it tars the
>current directory I'm in, and (now empty) directories for non-hidden
>directories. It does not include any files in any sub-directories.
>(expected behavior)

Not exactly:  It non-recursively stores all non-directories and
non-hidden directories (but not any contents of them), lying in the
current directory, but not the current directory itself, in the archive.

>4. However, when I perform a tar -cf somefile.tar --no-recursion .  it
>tars an empty directory called . with no files nor directories in it
>what so ever. (not what I expected)

When tar non-recursively stores a directory, then it merely stores the
directory's owner, group, permissions and timestamps.  Its contents are
not stored.

Thus, if you tell it to store "." (i.e. the current directory), it will
do so, storing the owner, group, permissions, and timestamps of the
current directory, but not storing any directories or non-directories,
whose names are located in it.

You might take a look into the tar documentation (i.e. info pages), using
the index, looking for the entry "recursion".

>what is a simple way to non-recursively tar a directory that contains
>hidden files?

If you want to store a directory and all files (hidden or not hidden) in
it, then you have to tell tar of each filename that is to be stored in
the archive, either by enumerating its name in the argument list or by
feeding its name with the "--null" and "--files-from=-" option to tar's
standard input.

The command

$ {  printf '%s\000' '.' &&
     find . \
     \( \! \( \! -wholename '.' -type d \) -o -prune \) \
     \( \! \( \! -type d \) -o -exec printf '%s\000' '{}' + \)
  } | tar -c -f ../somefile.tar --null --files-from=- --no-recursion

tells tar to non-recursively store the current directory and each
non-directory (hidden or non-hidden) that is located in the current
directory.
-- 
Wer mir E-Mail schreiben will, stelle   | When writing me e-mail, please
bitte vor meine E-Mail-Adresse meinen   | precede my e-mail address with
Vor- und Nachnamen, etwa so:            | my full name, like
Helmut Waitzmann <address@hidden>, (Helmut Waitzmann) address@hidden




reply via email to

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