Renaming file within zip archives - Unix

This is a discussion on Renaming file within zip archives - Unix ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Renaming file within zip archives

  1. Renaming file within zip archives

    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.

  2. Re: Renaming file within zip archives

    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

  3. Re: Renaming file within zip archives

    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.


  4. Re: Renaming file within zip archives

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

+ Reply to Thread