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.
Categories