LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-20-2008, 12:06 AM   #1
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Rep: Reputation: 15
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.
 
Old 11-20-2008, 12:18 AM   #2
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
Quote:
Originally Posted by prakash.akumalla View Post
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/*
 
Old 11-20-2008, 12:50 AM   #3
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
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.
 
Old 11-20-2008, 12:57 AM   #4
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
http://linux.die.net/man/1/zip
 
Old 11-20-2008, 01:04 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Bzip and bzip are more often used to compress files in Linux and Unix.
 
Old 11-20-2008, 01:05 AM   #6
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
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.

Last edited by prakash.akumalla; 11-20-2008 at 01:10 AM.
 
Old 11-20-2008, 01:43 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
Old 11-20-2008, 01:58 AM   #8
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
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.
 
Old 11-20-2008, 02:17 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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
 
Old 11-20-2008, 03:34 AM   #10
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
Thanks for your reply. I will have a look at it.

Prakash.
 
Old 11-20-2008, 04:08 AM   #11
dasy2k1
Member
 
Registered: Oct 2005
Location: 127.0.0.1
Distribution: Ubuntu 12.04 X86_64
Posts: 958

Rep: Reputation: 35
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
 
Old 11-20-2008, 11:43 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Zip File raja Linux - General 4 06-13-2006 02:14 AM
create a self-extracting zip file with zip on solaris? samsolaris Solaris / OpenSolaris 3 10-15-2004 02:50 AM
zip the file ashley75 Linux - General 1 05-01-2004 01:52 PM
Zip File Help :D neozero62 Linux - Newbie 2 01-11-2004 05:59 PM
zip file athenerx Linux - Newbie 1 06-24-2001 07:15 PM


All times are GMT -5. The time now is 12:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration