How do I easily manipulate individual files in a zip archive?

I have seen zip files used as containers for hand off between programs. Java’s JAR files are just zip archives.  Sometimes you just want to modify a file in a zip archive or view a file in a zip archive and this article will give you some quick steps to do that…

To extract a single file from an archive:

unzip MyTest.zip MyJavaFx.css
unzip MyTest.jar MyJavaFx.css

This will extract only the MyJavaFx.css from the MyTest.{zip,jar} file. Normally, one would want to modify this file and then put it back into the archive, and that can be done with:

zip MyTest.zip MyJavaFx.css
zip MyTest.jar MyJavaFx.css

You may also find that you just want to view a file in an archive, but don’t necessarily want to extract it to disk, well you can just stream the data out and then pipe it to another program like cat or vi:

unzip -p MyTest.zip MyJavaFx.css | gvim -
unzip -p MyTest.zip MyJavaFx.css | cat

The unzip -p switch just tells zip to stream. For vi and gvim the – means to read from STDIN.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s