LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can i zip a file (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-zip-a-file-684784/)

prakash.akumalla 11-19-2008 11:06 PM

How can i zip a file
 
Hai,

I have written a script in perl which writes some data to a file. As the data written in that file is more, and the size of that file is more, I want to zip the file after the data being written to it.

Please help me to do this.

Thanks,
Prakash.

RMLinux 11-19-2008 11:18 PM

Quote:

Originally Posted by prakash.akumalla (Post 3348258)
Hai,

I have written a script in perl which writes some data to a file. As the data written in that file is more, and the size of that file is more, I want to zip the file after the data being written to it.

Please help me to do this.

Thanks,
Prakash.

use: zip -r [new.zip] [path]
example. zip -r var.zip var/*

prakash.akumalla 11-19-2008 11:50 PM

Hi,

Thanks for your reply.

I tried
zip -r new.zip /tmp/new.csv

and also
zip -r /tmp/new.zip /tmp/new.csv

but in both instances its saying that there is a syntax error.

Can you please post me the complete syntax.


Thanks,
Prakash.

AuroraCA 11-19-2008 11:57 PM

http://linux.die.net/man/1/zip

jschiwal 11-20-2008 12:04 AM

Bzip and bzip are more often used to compress files in Linux and Unix.

prakash.akumalla 11-20-2008 12:05 AM

Hi,
I am not trying to add any thing to an existing zip file. I just want to decrease the size of the file(compress) by converting it to a zip file.

Please help me in doing so.


Thanks,
Prakash.

Nylex 11-20-2008 12:43 AM

Why don't you just bzip or gzip it then, as jschiwal suggested? Read the man pages for bzip2 and gzip for more info on how to use those.

prakash.akumalla 11-20-2008 12:58 AM

Hai,

Thanks for your reply.
I just converted a tar file for that file which decreases its size for almost 10%.

My problem is solved.

Thanks,
Prakash.

jschiwal 11-20-2008 01:17 AM

Tar has an option (-z) for gzip and (-j) for bzip. If you only have a single file, you can use gzip & bzip2 on there own. For a single file, you can also expand them using zcat (gzip files) and bzcat (bzip2). This would allow you to do things like grep for a pattern inside a compressed file:
example:
zcat /proc/config.gz | grep NLS

prakash.akumalla 11-20-2008 02:34 AM

Thanks for your reply. I will have a look at it.

Prakash.

dasy2k1 11-20-2008 03:08 AM

in general if you add -z to tar you get a .tar.gz file that is quite quick to compress and has a reasonable compression,

if you use -j you get .tar.bz2 that is slower to compress but is a better compression level

i92guboj 11-20-2008 10:43 AM

There are literally dozens (if not hundreds) of perl modules to deal with compressed files on any imaginable format. Since your script is written in perl, I think that it would make more sense to use one of these modules.


All times are GMT -5. The time now is 09:30 PM.