Skip to content

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 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 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 MyJavaFx.css | gvim -
unzip -p MyJavaFx.css | cat

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

TheSoftwareProgrammer View All

I like science and writing software.

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: