GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 31 of 47    Print  
How to compress files by using shell scripting

  
Total Answers and Comments: 4 Last Update: November 03, 2007     Asked by: ayypss 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 09, 2007 03:30:54   #1  
Jitu        

RE: How to compress files by using shell scripting
Hi All To compress a file or set of files you can use the gzip command in UNIX.



To zip a single file use:-

$ gzip filename .



It will create a file named filename.gz .

To zip a folder first create a .tar file and then zip it.

Let the name of the folder be shell .



To create a .tar file use:-

$ tar cvf filename.tar shell/.

It will create a file named filename.tar



Now use the $ gzip filename.tar .

It will create a file named filename.tar.gz .

So in this way you can compress a file.



Note: To uncompress a file you can use gunzip command.



Please make me understand if i am wrong. I will appreciate your help.



Thanks

Jitu

 
Is this answer useful? Yes | No
March 13, 2007 08:16:17   #2  
Shailendra        

RE: How to compress files by using shell scripting
Fantastic explaination given above......

another way would be...

compress <filename>
which will create a filename.Z
and if we want the zip file to be in some other folder

compress -cf <filename>


to uncompress
use the following command...
uncompress <filename>

 
Is this answer useful? Yes | No
April 20, 2007 00:33:04   #3  
Kailash        

RE: How to compress files by using shell scripting
Though the explanations given are very good but in real time environment where the file size runs into MBs of data the proper way would be

1: If its a single file then gzip and compress and pack will serve the purpose. Out of these compress gives the more desired results
These
commands use different compression algorithms take different amounts of time
and reduce files by different amounts.

In general these commands can reduce the size of a file by 50-75 .











Command SyntaxFile Produced
gzipgzip .gz
zip zip .zip
compress compress .Z
packpack .z

2: In case of a directory with a content of directory tree inside its better to first tar the main directory and then use compress option to reduce the size.

 
Is this answer useful? Yes | No
November 03, 2007 04:41:59   #4  
zorba        

RE: How to compress files by using shell scripting
tar -cvjf <filename.tar.bz2> <destiantion>
bz2 gives max compression.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape