# # Undoing bad archives
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Undoing bad archives

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© October 2005 Tony Lawrence
October 2005

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 you found something useful today, please consider a small donation.



Got something to add? Send me email.





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

Printer Friendly Version

->
-> Undoing bad archives


Inexpensive and informative Apple related e-books:

Take Control of iCloud, Fifth Edition

Take Control of Parallels Desktop 12

Photos for Mac: A Take Control Crash Course

Photos: A Take Control Crash Course

iOS 10: A Take Control Crash Course





More Articles by © Tony Lawrence





Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





Today the theory of evolution is about as much open to doubt as the theory that the earth goes round the sun. (Richard Dawkins)




Linux posts

Troubleshooting posts


This post tagged:

Basics

Shell



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode