Fix Corrupted Zip Files in Linux [Quick Tip]


It’s been a long time since I have talked about Linux, so here is something to get started again. This post talks about a common problem, Corrupted Zip Filewhich people face while downloading zip files from the Internet.

Not all the zip files can be recovered but using a few simple commands, you can try and recover the content without having to re-download the file again.

You can easily repair repairablezip files downloaded on Linux by issuing the following command;

zip F filename.zip

Issuing this command will tell the zip command to try to fix the zipfile if necessary. You can also issue the following command to make it the zip command work more harder on fixing the zip file.

zip FF filename.zip

I initially used this command as a patch to a shell script that read contents from a zip file, that was uploaded by a wizard, the patch was put in for zip files which were corrupted when uploaded over slower Internet connections.

Here is a part of the shell script for the geeks and power users reading Techie Buzz.

   1: unzip -tqqq $x >> /dev/null;
   2:     if [ $? -ne 0 ]; then
   3:       #Run Recovery mode first - do not remove this code - kd
   4:       zip -FF $x;
   5:       unzip -tqqq $x >> /dev/null;
   6:       if [ $? -ne 0 ]; then
   7:         echo "Could not unzip $x. Renaming it to BADZIP-$x";
   8:         mv $x BADZIP-$x;
   9:         continue;
  10:       fi
  11:     fi

Enjoy and look forward to more Linux Tips.

  • Share

Related Topics Similar to This Article: »

Recent Activity: »

Read More On:

Comment Using Facebook

6 Responses to this Article | Share your Opinions/Comments

We moderate comments to prevent spam. Moderation is done within few hours. Please try and stay on topic and refrain from using abusive language. If you think there is a problem with this post, please email the post author or send us an email at tips@techie-buzz.com with the URL and the problem you see and we will rectify it as soon as we can.

  1. abhishek on July 17th, 2008 at 10:33 am #

    gud tip, keep them coming more.

  2. Raj on July 17th, 2008 at 11:24 am #

    Nice Tip.
    Thanks

    Stumbled

  3. Dave Miller on April 27th, 2010 at 6:33 pm #

    So, what do you suggest if zip -FF still doesn't file the problem:

    [dave@bend cng258]# zip -FF recovered_tysonorc.zip –out rebuilt.tysonorc.zip
    Fix archive (-FF) – salvage what can
    Found end record (EOCDR) – says expect single disk archive
    Scanning for entries…
    copying: tyson&orc.jpg (48494 bytes)
    Central Directory found…
    EOCDR found ( 1 48596)…
    [dave@bend cng258]# unzip rebuilt.tysonorc.zip
    Archive: rebuilt.tysonorc.zip
    [rebuilt.tysonorc.zip] tyson&orc.jpg password:
    replace tyson&orc.jpg? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
    inflating: tyson&orc.jpg
    error: invalid compressed data to inflate

    Cheers,
    Dave

  4. Chatty on February 28th, 2011 at 3:21 am #

    Thanks, It certainly worked for me

  5. spiriad on March 30th, 2011 at 3:06 am #
  6. WannaBeGeekster on December 11th, 2011 at 3:25 am #

    Thanks for the script. This is great for looping over large collections.