Operating System - HP-UX
1752586 Members
4252 Online
108788 Solutions
New Discussion юеВ

How to create compressed file

 
kumar_choudhury
Occasional Advisor

How to create compressed file

Hi,

I want to create compressed file out of so many files. Can any one suggest how crate a compressed file out of more then 2000 no of files.
8 REPLIES 8
Yang Qin_1
Honored Contributor

Re: How to create compressed file

You didn't specify where are those +2000 files located, in a single directory, several directories?

You can first make a tar backup file (like winzip).
# tar cfv /a/big/dir/myarch.tar dir_contain_files_and_subdirs
# gzip /a/big/dir/myarch.tar

If you want to create +2000 zip files,

# cd dir_with_files
# for file in *
# do
# gzip $file
# done

Yang
H.Merijn Brand (procura
Honored Contributor

Re: How to create compressed file

use GNU tar

# find /your/dir | gtar -T - -czf /tmp/archive.tgz

Or create an index in /tmp/index

# gtar -T /tmp/index -czf /tmp/archive.tgz

If it's mostly ASCII files (text), use bzip for (much) better compression. This example doesn't require GNU tar:

# cat index | xargs tar cf - | bzip2 -9 >/tmp/archive.tbz

So many other solutions exist

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Peter Godron
Honored Contributor

Re: How to create compressed file

Kumar,
please allocate points to answers.
Please see:
http://forums1.itrc.hp.com/service/forums/helptips.do?#22
Your profile shows 0 points to 13 answers !

tar cvf /dest/files.tar ./*
then
gzip /dest/files.tar
or
compress /dest/files.tar

For more info:
"man tar"
"man compress"

If tar blows out due to number of files back up the directory.
H.Merijn Brand (procura
Honored Contributor

Re: How to create compressed file

Don't use HP tar on itself:

# tar cf file.tar file ....
# gzip file.tar

Will easily hit the 2 Gb limit.
Use streaming mode instead

# tar cf - file ... | gzip -9 >file.tar.gz

Extra remark, even if GNU tar supports bzip2 as a command line option, be warned that it is not a builtin, but tar will use the external bzip2 command. gzip *is* builtin.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Christian Tremblay
Trusted Contributor

Re: How to create compressed file

You really have a choice here, you can use either gzip, compress, pack, compact.

For more details about each of those utilities particular features, check their respective man pages.
Patrick Wallek
Honored Contributor

Re: How to create compressed file

Another option would be for you to install zip on your HP-UX machine.

You can find zip here:
http://hpux.connect.org.uk/hppd/hpux/Misc/zip-2.32/

If you will need to unzip on the HP-UX machine you will also need to install unzip:
http://hpux.connect.org.uk/hppd/hpux/Misc/unzip-5.52/

Once zip is installed you can do a:

# zip /dir/myfiles.zip /dir/file1 /dir/file2 /dir/file3

and just continue listing files.

For full usage instructions:

# zip -?
Rory R Hammond
Trusted Contributor

Re: How to create compressed file


A directory and all its files and sub directires.

cd /directory
find . -print |cpio -o |gzip >list.gz

all files with a .sh extension
find / -name "*.sh" |cpio -o |gzip > /tmp/shells.gz

To extract
mkdir /recover_dir
cd /recover_dir

gunzip /directory/list.gz
cpio -idmu < /directory/list

gunzip /directory/shells.gz
cpio -idmu < /directory

If you really mean compress use compress instead of gzip.

Rory

There are a 100 ways to do things and 97 of them are right
Nikunj Purohit
New Member

Re: How to create compressed file

Use tar -cvf and then gzip the compressed file.