> It seems some files are present multiple times in your list.
> 
> echo text >file.txt
> tar cvWf test.tar file.txt file.txt
> tar tvf test.tar

Sorry, I deleted this message, and then had a thought a few minutes later,
so I'm quoting text from the mailing list archive.

With this new information, it occurs to me that perhaps the OP did
something like this:

unicorn:/tmp/x$ echo hello > file.txt
unicorn:/tmp/x$ ls -l
total 4
-rw-r--r-- 1 greg greg 6 Sep 20 07:05 file.txt
unicorn:/tmp/x$ find . | tar cv --files-from=- -f ../foo.tar
./
./file.txt
./file.txt
unicorn:/tmp/x$ tar tvf ../foo.tar
drwxr-xr-x greg/greg         0 2022-09-20 07:08 ./
-rw-r--r-- greg/greg         6 2022-09-20 07:05 ./file.txt
hrw-r--r-- greg/greg         0 2022-09-20 07:05 ./file.txt link to ./file.txt

Feeding an *unfiltered* "find ." listing to tar --files-from=- will
cause this behavior, because find supplies the directory names as well
as the file names.  tar will recurse into the directories (specified by
name), and then also grab the files (specified by name).

If you want to avoid that, you have two (well, more than two) choices:

1) Tell find not to supply directory names.  This means you won't archive
   any empty directories.

2) Tell tar not to recurse into named directories.

For #1 you'd have:

unicorn:/tmp/x$ find . -type f | tar cv --files-from=- -f ../bar.tar
./file.txt
unicorn:/tmp/x$ tar tvf ../bar.tar
-rw-r--r-- greg/greg         6 2022-09-20 07:05 ./file.txt

For #2 it would be:

unicorn:/tmp/x$ find . | tar cv --no-recursion --files-from=- -f ../baz.tar
./
./file.txt
unicorn:/tmp/x$ tar tvf ../baz.tar 
drwxr-xr-x greg/greg         0 2022-09-20 07:08 ./
-rw-r--r-- greg/greg         6 2022-09-20 07:05 ./file.txt

For kicks, I'll also give option #3, which is:

3) Use cpio or pax, which are designed to accept find's output.  Not tar.

But of course nobody will ever listen to that.  tar is *much* too popular,
to the point where most people don't even realize there are other choices.

Finally, I'll end by citing an earlier message:

> What are the *exact* tar commands that you used, to create the archive,
> and to get that partial listing that you gave?

There's a reason we ask that kind of question.  If this message turns
out to be an accurate diagnosis of the problem, then the fact that the
OP refused to give us their exact tar commands led to a huge delay in
getting their answer.

Reply via email to