Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-01-2008, 09:09 AM   #1
LQ Newbie
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
Question How to calculate time required for compressing using zip?

Hello All,

I need to compress a tar file using zip in a shell script.
Is there any way in which i can estimate the time required to compress the file before actually compressing it using zip?

Old 08-01-2008, 11:39 AM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,877

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
One way to do it would be three commands in sequence:
1) date (formated to show hour,minute,second)
2) zip filename
3) date

Then subtract first date from second date to get the answer.

Or, try using the time command to time the zip operation.

Last edited by bigrigdriver; 08-01-2008 at 11:40 AM.
Old 08-01-2008, 11:51 AM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
bigrigdriver, I think the question is about estimating the time needed by the zip command, before actually execute it. My answer is no. The time required by the compression algorithm depends on:
1. the size of the original file
2. the kind of data inside the file
3. the load of the machine
4. the performance of the filesystem I/O
5. ...
you can only do a rough estimate based on the file size, which is the only information you can get in advance. Just my opinion.
Old 08-01-2008, 12:40 PM   #4
Senior Member
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,059

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
Yeah, but...

I would agree that you can't really calculate the time to compress a general file. You might, however, be able to measure the time to compress a similar file, depending on what you know about the files that you are going to want to compress. In many cases, getting an estimate of the worst-case time (greatest time that it could take) is enough. In which cases the 'how do you time...' come into their own.

I'm not sure that OP will get more useful information unless more can be disclosed about the application.
Old 08-01-2008, 12:51 PM   #5
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
It is much more usual to use gzip to compress a .tar file, and there is no need to do it as a separate phase - just add the z option when making the tar file in the first place, and it will be created compressed.

A zipped tarball is unusual. Like tar files, zip files are a "filesystem in a file" - you can store multiple files and so on. They're not as suitable for accessing from a tape drive (which tar files were originally designed to do, but they include compression, which a tar file does not do on it's own.

So I would expect either .zip or .tar.gz (a gzipped tar file), or .tar.bz2 (a tar file compressed with the bzip2 program, which takes longer than gzip, but often results in a smaller size). You might also see .tar.Z, which is a tar file which has been compressed using the unix "compress" program.

Unlike zip, gzip, bzip2 and compress do not contain multiple files - they just contain a compressed version of one file.

I agree with the replies which say it is not really feasible to pre-calculate the time it will take to compress a file. There are too many variables. Your best bet is to do some tests with a system under common working loads, and get a feel for roughly how long it will take. Note that the runtime will rise sharply as the machine becomes heavily loaded.

Last edited by matthewg42; 08-01-2008 at 12:52 PM.
Old 08-02-2008, 12:11 AM   #6
LQ Newbie
Registered: Aug 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thumbs up Thank you

Thank you for all the help and suggestions!



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
how to calculate program excecute time. UltraSoul Programming 1 04-16-2008 09:41 PM
How to calculate the StackSize Required ebinjose Linux - Kernel 1 02-03-2008 02:47 PM
compressing a directory with zip utility ahmedb72 Solaris / OpenSolaris 2 07-04-2007 10:25 AM
get or calculate mp3 songs time unabia Linux - Software 3 12-04-2006 08:29 PM
calculate time difference between 2 formatted timestamps nickleus Linux - General 3 05-12-2006 11:08 PM

All times are GMT -5. The time now is 03:32 PM.

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