Unix administration - Renaming file within zip archives

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > April 2005 > Renaming file within zip archives





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Renaming file within zip archives
khoa nguyen

2005-04-06, 8:48 pm

Hi,

I would like to zip from stdin, e.g. through some pipe, into a zip
archive. When I unzip the file I would get "./-" as the unzipped file.
I'd like to unzip to some other logical name and not "./-".

For example,

[begin scenario]
% echo 'hello world' | zip > hello.zip
% unzip hello.zip
[end scenario]

unzipping hello.zip will produce a "./-" file.

Thanks in advance,
Khoa.
Ulrich Hobelmann

2005-04-06, 8:48 pm

khoa nguyen wrote:
> Hi,
>
> I would like to zip from stdin, e.g. through some pipe, into a zip
> archive. When I unzip the file I would get "./-" as the unzipped file.
> I'd like to unzip to some other logical name and not "./-".
>
> For example,
>
> [begin scenario]
> % echo 'hello world' | zip > hello.zip
> % unzip hello.zip
> [end scenario]
>
> unzipping hello.zip will produce a "./-" file.


Zip is a container format, like tar. It can contain more than one
file, so zipping from standard input would be difficult.

If you just want to zip one file, use gzip instead. With
parameter -9 it has much better compression, too.
% cat foo.txt | gzip -9 > foo.txt.gz
% gunzip foo.txt.gz
qazwart

2005-04-07, 6:11 pm

The "zip" command contains files and not strings. You're getting the
"-" because you're attempting to zip from STDIN, and not pass the "zip"
command a file to zip.

Like "tar", "zip" can operate on STDIN and STDOUT if you give it a "-"
for a filename.

For example:

zip -r - . | | dd of=/dev/nrst0 obs=16k

Would produce a zip archive directly to tape device /dev/nrst0

Since most compression algorithims depend upon the entire file to work,
I'm not too sure if a utility that does exactly what you want exists.

I've tried what you did, but can't seem to get it to compress the
string "hello world". You can try the "zcat" command on "hello.zip" to
see if it will print out the string "hello world", but I'm not too sure
it will work.

khoa nguyen

2005-04-10, 8:48 pm

> Since most compression algorithims depend upon the entire file to work,
> I'm not too sure if a utility that does exactly what you want exists.


I'm sending files to windows machines. The problem is that windows
does not like downloaded files with multiple extensions, e.g.
"foo.txt.gz". That's why I resort to zipping from stdin. And
perhaps...rename "-" to "foo.txt"?

The alternative is:

% echo "hello world" > foo.txt
% zip foo foo.txt

> I've tried what you did, but can't seem to get it to compress the
> string "hello world". You can try the "zcat" command on "hello.zip" to
> see if it will print out the string "hello world", but I'm not too sure
> it will work.


I think "hello world" is too small a string to illustrate any amount
of compression at all. If you zip larger files the amount of
compression will be more appreciable.

"zcat" does print out "hello world".

Thanks for all your replies,
Khoa.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com