This tutorial will show you how to zip up a folder as a tar.gz then extract the contents of a tar.gz. First start by going to the directory that contains the file that you want to compress. For demonstration purposes I will create a new folder and zip it up. Then delete the folder and unzip it to show the process working.
To make this tutorial easier you should cd to the directory that contains the folder that you want to zip. e.g cd /tmp
To compress the folder we will use the tar command. You will then provide the name that you want to use for the archived file/folder and the name of the file/folder you want to archive.
tar -pczf zippedarchive.tar.gz zipme
Use ls to check that the process was successful. You should see your newly created archive listed on the screen. You have successfully created a tar.gz archive! Now let us unzip it.
Start by removing the old directory that we just zipped up.In this case I want to delete the directory called delete zipme. Use rmdir /zipme to delete the directory and use ls to check that is has successfully been deleted. Now you can extract the archive.
To Extract a tar.gz archive you can use the tar command again.
[root tmp]# tar xvsf zippedarchive.tar.gz
Use ls to check that the directory was successfully extracted. Below is the full process of creating a directory, archiving it, then extracting it with validation steps in between.
[root tmp]# mkdir zipme [root tmp]# ls zipme [root tmp]# tar -pczf zippedarchive.tar.gz zipme [root tmp]# ls zipme zippedarchive.tar.gz [root tmp]# rmdir zipme [root tmp]# ls zippedarchive.tar.gz [root tmp]# tar xvsf zippedarchive.tar.gz zipme/ [root tmp]# ls zipme zippedarchive.tar.gz