Operating System - HP-UX
1820636 Members
1980 Online
109626 Solutions
New Discussion юеВ

how to zip and unzip file

 
Mousa55
Super Advisor

how to zip and unzip file

Hello
how to zip and unzip file and directory in unix server.
and are i can use tar command for that

thanks

6 REPLIES 6
Patrick Wallek
Honored Contributor

Re: how to zip and unzip file

If you install 'zip' and 'unzip' on your HP-UX machine, then you can use those utilities.

Zip is here:
http://hpux.connect.org.uk/hppd/hpux/Misc/zip-2.32/

Unzip is here:
http://hpux.connect.org.uk/hppd/hpux/Misc/unzip-5.52/

Tar itself cannot compress, but you can certainly create a tar file containing a directory and then you can compress that tar file.

If you want to create a tar-file containing 'somedir' you could do it several ways.

1) Create it with relative paths so you can extract it ANYWHERE later on

# cd /somedir
# tar -cvf ../somedir.tar .

Will create a tar file in the parent of 'somedir' called somedir.tar. You can then compress this with compress or gzip.

# compress somedir.tar
or
# gzip somedir.tar

2) If you want to create a tar file with explicit paths to somedir and then compress it you can do:

# cd /var/tmp
# tar -cvf somedir.tar /somedir
# compress somedir.tar
or
# gzip somedir.tar
Matti_Kurkela
Honored Contributor

Re: how to zip and unzip file

There is also a trick: if you cannot install any extra software on the HP-UX but there is a Java SDK already installed (usually in /opt/java/bin), you can use the "jar" tool of the Java SDK to create or extract zip files.

The "jar" tool is used exactly like "tar" but the .jar files it creates are 100% compatible with .zip files. If you use "jar" to package a set of files, it will automatically generate one extra file named "Manifest" to the package; it's related to jar's use with Java, just ignore it.

MK
MK
Dennis Handly
Acclaimed Contributor

Re: how to zip and unzip file

>Patrick: 1) Create it with relative paths so you can extract it ANYWHERE later on

You can also use the -C option:
$ tar -cvf somedir.tar -C /somedir .

And you could also use pax(1) to rename any existing path in your tar archive, when extracting.

>You can then compress this with compress or gzip.

You can also do this in one step:
$ tar -cvf - . | gzip > ../somedir.tar.gz
Steven Schweda
Honored Contributor

Re: how to zip and unzip file

Note that Zip 2.32 and UnZip 5.52 are limited
to files (and archives) smaller than 2GB.
Zip 3 and UnZip 6 should remove that
limitation, but they have not yet been
released. For the latest pre-release
("BETA") kits, see:
ftp://ftp.info-zip.org/pub/infozip/beta/
The size limitations for "tar" depend on
whose "tar" you use.

If you use "tar" and want compression, most
people do both in a pipeline:

tar cf - whatever | gzip -c > whatever.tgz

gzip -cd whatever.tgz | tar xfo -

Details depend on which options you want.

More details depend on why you want to do any
of this.
Mousa55
Super Advisor

Re: how to zip and unzip file

Hello
i want to zip an unzip to any file and directory
not only .tar
thanks
Steven Schweda
Honored Contributor

Re: how to zip and unzip file

> i want to zip an unzip to any file and
> directory
> not only .tar

Huh? When used properly, either [Un]Zip or
"tar" can do almost anything to any file or
directory. Can you explain more clearly what
you want to do? An example might help.

Or go back and look at those "tar"
suggestions more carefully.

> # tar -cvf ../somedir.tar .

There's a dot (current directory) at the end
of that line. "man tar"?

(I'm starting to get that feeling again that
this is all hopeless.)