Jump to content

How to Clean Up after a Tarball or Zipball Explodes

0
  mike-loukides's Photo
Posted Jan 29 2010 05:53 PM

Don't you hate it when someone sends you a big fat tar or zip file full of lots of files, and didn't bother to put everything in one folder? If you extract it unawares, you get dozens--maybe hundreds--of files littering your working directory.

However, the bash shell makes it easy enough to delete everything. For a tar file, this command deletes everything that was extracted from the tarball:

$ rm `tar tfz sometarball.tgz`

Zip files are tougher, since Zip utilities usually don't have a command line interface. But if you have Java installed, you can do the same thing. Java has a jar command that's very similar to tar, but works on Zip archives. (It has a few extensions, but those are irrelevant here.) So here's how you clean up after an exploding zip file:

$ rm `jar tf somezipball.zip`

Syntactically, these two commands are identical. They both list all the files in the archive, then pass the result to the rm (Unix/Linux delete) command. The z option in the tar command tells tar that it's dealing with a compressed file. If the file isn't compressed (normally the case if the file extension is just .tar), omit it. The z option isn't needed with the jar commands; zip files are always compressed.

Cover of Learning the bash Shell
Learn more about this topic from Learning the bash Shell, 3rd Edition. 

This refreshed edition serves as the most valuable guide yet to the bash shell. It's full of practical examples of shell commands and programs guaranteed to make everyday use of Linux that much easier. Includes information on key bindings, command line editing and processing, integrated programming features, signal handling, and much more!

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies