On a remote server running Linux Ubuntu 16.04', I ran out of space while doing a tar file from a bunch of old .rar files (~150G), and now the end tar is 'corrupt'. That is when doing a tar tf I get:

tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

How can I fix this corrupted tar?

I've tried to:

  • delete the truncated file from the tar (tar --delete -f mycorruptedtar.tar offendingfile.ext)
  • repair it by extracting the files that aren't corrupt and adding them to a new tar by doing


for file in $(tar -tf mycorruptedtar.tar);
        if [ ! "$file" == "offendingfile.ext" ]
                tar xf mycorruptedtar.tar $file
                tar rf newtar.tar $file --remove-files
                tar --delete -f mycorruptedtar.tar $file
  • I also tried using a hex editor to remove the last part of the file which I assume is where lies the problem, but I chickened out because I didn't know exactly how or what to fix and I didn't want to worsen things.

Any ideas?

  • What is the real problem? When you get Unexpected EOF in archive, tar has already unpacked what it could (all complete files and even bits of the truncated file). So, unlike a ZIP, the truncated tar is usable. – xenoid Sep 5 '17 at 15:12
  • I want to fix the tar before adding the rest of the files I still need to add to the tar... Maybe another option would be to just make a new tar with the other files and keep this 'functioning corrupt tar'... I also wanted to know how to fix the file, if possible – arod Sep 5 '17 at 15:18
  • Theoretically it should be possible to compute position of the end of the last good file, truncate the TAR there and append the end-of-archive marker. But IMHO de-tarring what you can and re-tarring it will be easier and less risky. – xenoid Sep 5 '17 at 20:41
  • I agree with you advice. I was just wondering if there was an automated tool/method to help me fix the file task before setting up a new volume with enough space to do the 'de-tarring/re-tarring'. – arod Sep 5 '17 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.