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.


Hate these ads?

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.




ad

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
22465923 4,457

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. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Shell
       - Basics




Unix/Linux Consultants

Your ad here - $48.00 yearly!

http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering



Twitter
  • Nov 21 07:55
    @loudmouthman: correct, but how do you prove ANYTHING like that is accurate? You can't. A text file is no better or worse than anything.
  • Nov 21 07:40
    @loudmouthman: well, a digital signature could prove it hadn't been altered. Text is no more insecure than anything else in that sense.









Change Congress


Related Posts