Sunday, 21 April 2013

Sample UNIX script to compress and uncompress files - Use of the gzip, tar, zip command

There are different ways of creating file archive. Once, we create the archive, we need to know how to extract the file back and use it.

The below commands work great to achieve our goal:

Archive creation and extraction:

Using the tar command:
  1. tar -cvf TEST.tar ./*   - Running this command compresses all the files located in current       directory into TEST.tar file
  2. tar -xvf TEST.tar - This command will extract all the files from the archive TEST.tar
  3. tar -tf TEST.tar - This command will list all the files in the archive TEST.tar
Using the gzip command:
  1. gzip Test.txt  - This command will create a gzip file Test.txt.gz
  2. To unzip the file - gunzip Test.txt.gz
Using the zip comand:

1. zip Test1 Test.txt - This will create a file Test1.zip
2. unzip Test1.zip -d /tmp/Test - This command will unzip the files in Test1.zip to the /tmp/Test path

Let us know if this was helpful !!

No comments:

Post a Comment

Please share your thoughts and let us know the topics you want covered