APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Basics > Undoing bad archives
Printer Friendly Version




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.


If this page was useful to you, please click to help others find it:  
Your +1's can help friends, contacts, and others on the web find the best stuff when they search.


Comments?




More Articles by Tony Lawrence - Find me on Google+



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


cartoon

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

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




Buy Kerio from a dealer who knows tech: I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals
pavatar.jpg

This post tagged:

       - Basics
       - Shell




Unix/Linux Consultants

Skills Tests

Guest Post Here