How to compress files by using shell scripting

Questions by ayypss

Showing Answers 1 - 4 of 4 Answers

Jitu

  • Feb 9th, 2007
 

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

  Was this answer useful?  Yes

Shailendra

  • Mar 13th, 2007
 

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>

  Was this answer useful?  Yes

Kailash

  • Apr 20th, 2007
 

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.

  Was this answer useful?  Yes

zorba

  • Nov 3rd, 2007
 

tar -cvjf <filename.tar.bz2> <destiantion>
bz2 gives max compression.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions