1

I hope this fits the category "programming question".

I have a tar-archive containing the folowing structure:

Folder1/File1
Folder2/File2
Folder3/File3
Folder4/File4

My goal is to extract specific contents from this archive (which is huge and therefore called hugeArchive.tar) in the following.

The data to extract is automatically generated and given to me via textfile "filesToExtract.txt".

Content of "filesToExtract.txt":

Folder1
Folder1/File1
Folder2
Folder2/File2

So I thought this task should be easy and I will do achieve it using

cat filesToExtract.txt | xargs tar -xvf hugeArchive.tar

On SunOS 5.10 this performes as expected but on Linux Redhat 6.8 I receive errors (though the general extraction still seems to work because the files are available afterwards)

Output SunOS 5.10:

x Folder1, 0 bytes, 0 tape blocks
x Folder1/File1, 386 bytes, 1 tape blocks
x Folder2, 0 bytes, 0 tape blocks
x Folder2/File2, 858 bytes, 2 tape blocks

Output on Linux Redhat 6.8:

Folder1/
Folder1/File1
Folder2/
Folder2/File2
tar: Folder1/File1: Not found in archive
tar: Folder2/File2: Not found in archive
tar: Exiting with failure status due to previous errors

I have no idea what is causing that so I played around and manually changed the input file filesToExtract.txt to look like this instead:

Folder1/File1
Folder2/File2

Now it works on Linux, witout any error messages. This made me wonder: Maybe this is an overwriting problem? Or maybe the tar tool somehow only allows accessing each file only one time?

I created another kind of test and changed filesToExtract.txt again and included a duplicate there:

Folder1/File1
Folder2/File2
Folder1/File1

...and there we have the identical error from the first attempt again:

Folder1/File1
Folder2/File2
tar: Folder1/File1: Not found in archive
tar: Exiting with failure status due to previous errors

I am clueless what is behind it (acutally tar should overwrite without complaining, shouldn' it?). Do you have any idea? Is my command wrong? What will I have to change, that it works on Linux without having to change the filesToExtract.txt.

By the way I am using the standard tar implementation on both systems.

Thanks a lot in advance!

EDIT:

tripleee suggested to rather use

xargs tar -xvf hugeArchive.tar <filesToExtract.txt

since this is a command using redirection. But this is only for the sake of clearness/effectivity and won't affect the overall problematic behaviour

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
and0r
  • 305
  • 1
  • 4
  • 13
  • 1
    [Here](http://www.linuxquestions.org/questions/linux-general-1/not-found-in-archive-error-when-extracting-a-list-of-specific-files-with-tar-4175517000/) someone is experiencing the same problem as you, where they extract the directory first, then the file and receive the error. They don't seem to get to the bottom of the problem however, there was a mention of hard links that sometimes cause that problem. Do you have hard links in your tar file? – FrankRalphBob Mar 27 '17 at 15:57
  • 1
    I like the question but you want to get rid of the [useless use of `cat`](http://www.iki.fi/era/unix/award.html); use a redirection `xargs tar -xvf hugeArchive.tar – tripleee Mar 27 '17 at 18:50
  • "the standard tar implementation on both systems" is probably different. While Linux is using GNU tar by default, I'm pretty sure that SunOS uses its own thing. I am not surprised there is a difference. Installing GNU tar on SunOS would give you the same behavior in both places. – larsks Mar 27 '17 at 20:24
  • @larsks Well, you are probably right (SunOS tar even provides another output displaying bytes and block information when extracting) but in the end I would rather have a solution, that is running using GNU tar without errors since I don't to port my error to SunOs but instead get rid of it on Linux :) – and0r Mar 28 '17 at 06:29
  • @FrankRalphBob No, there are no hard links in the tar-file. In your provided link the given error message (with hard-links) does look somehow different (it seems to incude a literal reference to the word "hard link"). This is not the case here. But the post #7 in that link seems to shows the same problem that I have here... – and0r Mar 28 '17 at 07:21

1 Answers1

0

I might be wrong, but it seems that there is no satisfying answer.

If I do a "manual" apporach on Linux RH 6.8 this will happen:

Test 1:

tar -xvf myHugeArchive.tar Folder1

This extracts Folder1 with its content (File 1). I can repeat that command as often as I want without needing to delete the extracted data (so tar -xvf does indeed overwrite, just as it is supposed to to).

Test 2:

tar -xvf myHugeArchive.tar Folder1/File1

This also works and creates the Folder1 and extracts File 1. I also can repeat this command as often as I want.

Test 3:

tar -xvf myHugeArchive.tar Folder1 Folder1/File1

This extracts the folder and the file, yes, but the process nevertheless fails (as expected) with the error depicted in the question.


Conclusion:

It dosn't work with GNU-tar that way (except there is a secret option parameter I don't know about...). In the end it seems like I have to preprocess and remove those "kind-of-duplicates" my filesToExtract.txt first.

and0r
  • 305
  • 1
  • 4
  • 13