spacer
Web Development Tutorials LINUX Tutorials
 Developer Newsletter

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

Web Hosting Directory
ASP.NET
Budget
Dedicated Servers
Ecommerce
Linux
Resellers
Shared
Small Business
Windows

Developer Manuals
Learn HTML
Learn PHP
Learn CSS
Learn AJAX
Learn JavaScript
Learn Pear
Free White Papers

Developer Resources
Developer Tools
Developer Content
Survey Software
Dedicated Servers




Undoing Bad Archives

By Tony Lawrence
2005-10-19


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.



Tutorial Pages:
» Undoing bad archives


© Copyright 2005 A.P. Lawrence


 | Bookmark Print |   Write For Us
Related Tutorials:
» How to Install PHP 5 on Linux
» How to Install Apache 2 on Linux
» How to Install MySQL 5.0 on Linux
» SMB Caching
» Mound --Bind
» Tar Wild Card Interpretation



About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: