APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Undoing bad archives

Most zip or tar archives are made so that they unpack into a sub-directory. However, every now and then you run into one that wasn't done that way, and if you happen to unpack it in a directory that already has files, you end up with confusion: what was just unpacked and what was already here?

Of course an "ls -lt" gives you some idea, though not for directories: you'll need just "ls -l" to see recent dates for any directories created by the archive.

For illustration, I created three empty files (a, b, c) in a directory and then unzipped an archive into it. The results of various "ls" commands are shown:

$ ls -l
total 17064
drwxr-xr-x   4 foo  group      136 Oct  7 16:35 BuildFiles
-rw-r--r--   1 foo  group    17984 May  5  2004 COPYING
drwxr-xr-x   3 foo  group      102 Oct  7 16:35 Cd
-r--r--r--   1 foo  group    15377 Oct 14  2003 Citrix EULA.txt
drwxr-xr-x   3 foo  group      102 Oct  7 16:35 Floppy
-rw-r--r--   1 foo  group     1099 May  5  2004 LICENSE
drwxr-xr-x   5 foo  group      170 Oct  7 16:35 RebuildIsoWithConf
-rw-r--r--   1 foo  group  8684127 Oct  7 16:35 Thinstation-2.1.1-prebuilt-LiveCD.zip
-rw-r--r--   1 foo  group     6263 Jul 28 13:01 _HowTo-LiveCD.txt
-rw-r--r--   1 foo  group        0 Oct  7 16:35 a
-rw-r--r--   1 foo  group        0 Oct  7 16:35 b
-rw-r--r--   1 foo  group        0 Oct  7 16:35 c
$ ls -lt
total 17064
drwxr-xr-x   4 foo  group      136 Oct  7 16:35 BuildFiles
drwxr-xr-x   3 foo  group      102 Oct  7 16:35 Floppy
drwxr-xr-x   5 foo  group      170 Oct  7 16:35 RebuildIsoWithConf
drwxr-xr-x   3 foo  group      102 Oct  7 16:35 Cd
-rw-r--r--   1 foo  group  8684127 Oct  7 16:35 Thinstation-2.1.1-prebuilt-LiveCD.zip
-rw-r--r--   1 foo  group        0 Oct  7 16:35 a
-rw-r--r--   1 foo  group        0 Oct  7 16:35 b
-rw-r--r--   1 foo  group        0 Oct  7 16:35 c
-rw-r--r--   1 foo  group     6263 Jul 28 13:01 _HowTo-LiveCD.txt
-rw-r--r--   1 foo  group     1099 May  5  2004 LICENSE
-rw-r--r--   1 foo  group    17984 May  5  2004 COPYING
-r--r--r--   1 foo  group    15377 Oct 14  2003 Citrix EULA.txt
 

What a mess. There's no easy way to identify what came from this archive if we didn't already know.

So, the easiest thing to do is to delete it and start over in a clean sub-directory. But how can you delete files if you don't know which ones should be deleted?

Not so hard, actually. Try this:

$ mkdir t
$ cd t
$ unzip ../Thinstation-2.1.1-prebuilt-LiveCD.zip
Archive:  ../Thinstation-2.1.1-prebuilt-LiveCD.zip
  inflating: COPYING                 
  inflating: Cd/thinstation.iso      
  inflating: Floppy/thinstation.profile/thinstation.conf.user  
  inflating: BuildFiles/thinstation.conf.buildtime.prebuilt-cd  
  inflating: BuildFiles/build.conf.prebuilt-cd  
  inflating: LICENSE                 
  inflating: Citrix EULA.txt         
  inflating: _HowTo-LiveCD.txt       
  inflating: RebuildIsoWithConf/rebuild-iso.bat  
  inflating: RebuildIsoWithConf/mkisofs.exe  
  inflating: RebuildIsoWithConf/cd-files/delme.txt  
$ for i in *; do rm -rf "../$i"; done
$ cd ..
$ ls -l
total 16968
-rw-r--r--   1 apl  staff  8684127 Oct  7 16:35 Thinstation-2.1.1-prebuilt-LiveCD.zip
-rw-r--r--   1 apl  staff        0 Oct  7 16:35 a
-rw-r--r--   1 apl  staff        0 Oct  7 16:35 b
-rw-r--r--   1 apl  staff        0 Oct  7 16:35 c
drwxr-xr-x   2 apl  staff       68 Oct  7 16:38 t
 

All clean. The files are in "t" and the mess is gone. Unless there were "." files in that mix; this script doesn't touch those. Add .[0-z]* if you must.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Undoing bad archives




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





Doing linear scans over an associative array is like trying to club someone to death with a loaded Uzi. (Larry Wall)

The idea that Bill Gates has appeared like a knight in shining armour to lead all customers out of a mire of technological chaos neatly ignores the fact that it was he, by peddling second rate technology, led them into it in the first place, and continues to do so today. (Douglas Adams)












This post tagged: